Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Email notification in jenkins based on a script output

I am stuck at a point where I run a perl script through jenkins and I want a conditional email notification to be sent.

For eg .. if at the end of script the value of a certain variable is > 1 then send the email notification else dont send

Can anybody help me with this ? or knows a better way to do this ?

like image 819
user2946704 Avatar asked Apr 10 '14 07:04

user2946704


People also ask

Does Jenkins have notification mechanism?

Jenkins comes with an out of box facility to add an email notification for a build project. Step 1 − Configuring an SMTP server. Goto Manage Jenkins → Configure System. Go to the E-mail notification section and enter the required SMTP server and user email-suffix details.

How do I use editable email notifications in Jenkins?

For a project to use this plugin, you need to enable it in the project configuration page. In the Post-build Actions section, click on Add post-build action and then select Editable Email Notification. There are three main fields that you can edit when this plugin is enabled: Project Recipient List.

How do I send an email after every build in Jenkins?

To send email, the plugin needs the smtp configured. Go to Manage Jenkins > Configure System > search for “Extended E-mail Notification”. Configure the smtp. Example: My configuration with gmail smtp.


2 Answers

I haven't any of this, however:

There is an Any Build Step plugin. Among other things, it allows post-build actions to be executed as build steps. In theory, this should allow you to execute "Editable Email Notification" post-build step as a build step. This is the biggest wildcard in this solution. Try this first. I don't know if the email notification will work properly when done before the Jenkins' "build cycle" of a job is complete.

Next, there is Conditional Build Step plugin. It allows you to execute a build step based on various conditions.

If you were able to trigger email in the middle of the build cycle with "Any Build Step" plugin, you should be able to wrap it with the "Conditional Build Step" plugin to be executed conditionally.

Let me know if this actually works

like image 108
Slav Avatar answered Sep 28 '22 10:09

Slav


I like siri's answer. There is one think missing.

logger.println(build.getLog(50)) if
(build.getLog(50).toString().contains("NoChangesPresent")) {   cancel = true; }

It doesn't appear that contains will function without converting it first to a string. Good luck!

like image 34
ryanvito Avatar answered Sep 28 '22 08:09

ryanvito