"Mail" Step for Jenkins Workflow

There are a number of great Jenkins plugins that provide email send/notification capabilities. These all work really well with traditional Jenkins Job types (Freestyle, Maven etc), not only handling the composition and sending of an email, but also make decisions around when/if that email should be sent based on the state of previous runs of the Job in question etc.

The nature of a Workflow Job is different from other build types in that the Job author has more direct control and visibility into the “flow” and state of the job. They are able to script the Job flow and monitor its state directly in the Workflow DSL (Groovy). For that reason, it makes sense to also provide a straight-forward mail step for Workflow that simply sends an email i.e where there’s no magic around email composition or scheduling of the send.

This is what the new mail step does for Jenkins Workflow. It’s built on top of the mailer-plugin, but provides a more logical interface for Workflow job types that simply want to send an email e.g.

node {
   // do some work...
   // We need to wait for input from someone in devops, so lets send them
   // an email before pausing the build for input...
   mail (to: 'devops@acme.com',
         subject: "Job '${env.JOB_NAME}' (${env.BUILD_NUMBER}) is waiting for input",
         body: "Please go to ${env.BUILD_URL}.");
   input 'Ready to go?';   
   // continue on ...
}

As usual, the Snippet Generator is the best way to investigate all the options available for this and other Workflow build steps.​

 

Tom Fennelly
Engineer
CloudBees

 

Add new comment