Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send an email from Jenkins only in a release?

I was trying to resolve this issue, and searching forums etc. and trying for myself, without success.

We have a jenkins job and there we use the Release Plugin (with a standard configuration)

release plugin config

In the job then we have the "Perform Maven Release" in the left side to generate a version (tag, change poms, etc.) This work perfect.

Release button on the left side

We want to send an email to the team when the release has been done.

I tried the enviroment variable that the release plugin sets (IS_M2RELEASEBUILD by default) and combine with the email-ext plugin plugin where I can attach a groovy script (advanced=>trigger=>script trigger)

trigger with the email ext plugin

And I tried a lot of scripts to active the email, and none works, my last chance was:

def env = System.getenv()
env['IS_M2RELEASEBUILD'] == 'true'

but when I perform the release we have not the email sent (so this script evaluate the conditional to false or whatever)

Anyone has this setup in his Jenkins?

Thanks a lot!

like image 666
ERNESTO ARROYO RON Avatar asked May 22 '13 06:05

ERNESTO ARROYO RON


People also ask

How do I send email after build in Jenkins?

Go to the Jenkins home page and click the 'Manage Jenkins' menu option. Then, select the 'Configure System' option. 7. Enter the SMTP server name under 'Email Notification'.

How do I install an email extension plugin in Jenkins?

Click the 'Available' tab present at the top of the 'Manage Plugin' page. Type 'Notification' in the 'Filter' field displayed at the top-right side of the 'Manage Plugin' page. Click the checkbox next to the 'Email-ext plugin' option and 'Email-ext Template Plugin' option. Click the 'Install without restart' button.


1 Answers

You need to use "Editable Email Notification" as "Post-build Action" and paste

def env = build.getEnvironment();
String isRelease = env['IS_M2RELEASEBUILD'];
logger.println "IS_M2RELEASEBUILD="+isRelease;
if ( isRelease == null || isRelease.equals('false')) {
  logger.println "cancel=true;";
  cancel=true;
}

as Pre-send Script, fill in your E-Mail(s) in "Project Recipient List" and add an "Success"-Trigger. (precondition is you have not changed the default "Release envrionment variable" in "Maven release build")

like image 53
user2198875 Avatar answered Sep 20 '22 06:09

user2198875