Jenkins : sending email notification when starting

2020-08-25 05:08发布

问题:

In Jenkins, Is there a way to send a mail when starting a build. I know there is a post-build email notification which sends mail to the given recipients after a successful or failure build. Similarly i am expecting something like pre build notification.

Also is there a conditional email like if username == null send to xyz@domain.com else send it to requestor.

Tried : couple of plugins but didn't help much as they were post-build plugins

回答1:

  1. Install the Email-ext plugin: https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin

Notice that a post build action will solve your problem even though what you intend is to send an e-mail before the build.

  1. After that, go to the job configuration and "Add Post Build Action" > "Editable Email Notification"

  2. Press Avanced Settings:

  3. Now, at Triggers, just add a new trigger and choose "Before Build"

For the second part, the solution is to put the recipient list in an environment variable (for example, a string parameter called EMAIL_RECIPIENT) and then use that in the editable email notification recipients list box as ${EMAIL_RECIPIENT}.



回答2:

If you have sendmail configured, just use the "Execute shell" section and write the code to send mails before the build starts.



回答3:

You can try the Extend Email-ext, it has the Before build in the Triggers section.

https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin



标签: jenkins