Email notification in jenkins based on a script output
Asked Answered
S

4

13

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 ?

Sussi answered 10/4, 2014 at 7:35 Comment(0)
S
5

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

Stylet answered 10/4, 2014 at 13:32 Comment(0)
H
6

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.
Haroun answered 30/6, 2014 at 8:50 Comment(0)
S
5

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

Stylet answered 10/4, 2014 at 13:32 Comment(0)
C
2

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.

Contrive answered 16/3, 2017 at 15:42 Comment(0)
M
1

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!

Mcneil answered 26/4, 2019 at 15:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.