Question

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 ?

Was it helpful?

Solution 2

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

OTHER TIPS

This can be solved using

Email-ext plug-in https://wiki.jenkins.io/display/JENKINS/Email-ext+plugin

And you can use the above link to view information regarding plugin

  1. if i'm correct you want to send mails based on your build condition result.
  2. you can use triggers for this in Editable email notification.
  3. you can use post build step and pre build steps to trigger emails based on your conditions
  4. you need to write a script for your requirement and place it in post & pre build steps.

I was having a similar condition where I need to send out an email when jenkins build log has a string. Here is how I handled in the presend script of the jenkins job.

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

I am trying to get the last 50 lines of build log and search through it to see if there is a string present. If it is present then I am setting cancel to true which would stop triggering the email from jenkins.

Hope this helps.

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top