Reputation: 314
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 ?
Upvotes: 13
Views: 21501
Reputation: 11
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!
Upvotes: 1
Reputation: 3744
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
Upvotes: 6
Reputation: 109
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.
Upvotes: 2
Reputation: 27485
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
Upvotes: 5