[workflow] Problems sending out e-mails on build failures

531 views
Skip to first unread message

Craig Rodrigues

unread,
Jan 7, 2016, 1:57:31 AM1/7/16
to Jenkins Users
Hi,

In my workflow script, I try to send out e-mails if the build fails on this line:

https://github.com/freebsd/freebsd-ci/blob/master/scripts/build/build-test.groovy#L190

In this execution of the workflow, the build clearly failed:

https://jenkins.freebsd.org/job/FreeBSD_HEAD_sparc64/19/flowGraphTable/

but the step to send out the e-mail did not run.  No e-mails were sent out.

Did I structure something wrong in my workflow script?
--
Craig

Tom Fennelly

unread,
Jan 25, 2016, 5:32:59 PM1/25/16
to Jenkins Users, rod...@freebsd.org
Seems like the link is stale. Did you try something like https://www.cloudbees.com/blog/mail-step-jenkins-workflow ?

Craig Rodrigues

unread,
Jan 25, 2016, 7:42:28 PM1/25/16
to Tom Fennelly, Jenkins Users
and did not send out mail on failure.  What is going on?

The blog post you referred to is OK for simply sending out e-mail,
but I want to use the logic in the Mailer class, because it has a lot of good
stuff for sending out e-mails on failures, and when failures turn into successes.

Thanks.
--
Craig

Craig Rodrigues

unread,
Jan 30, 2016, 8:50:01 PM1/30/16
to Tom Fennelly, Jenkins Users
I realized  that the Mailer step will not run at all unless currentBuild.result is explicitly set.

For example this does not work:

node {
   try {
       sh "rm /tmp/some_file_which_does_not_exit"
   } finally {
       echo "In finally closure"
// currentBuild.result is null here, so next step is a no op which does not run
step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'rodrigc@localhost', sendToIndividuals: true]) } }

while this seems to work:

node {
   def err = null
   
   try {
       sh "rm /tmp/some_file_which_does_not_exist"
   } catch (caughtErr) {
       err = caughtErr
   } finally {
       echo "In finally closure"

       if (err) {
           currentBuild.result = 'FAILURE'
       } else {
           currentBuild.result = 'SUCCESS'
       }
       echo "currentBuild.result: ${currentBuild.result}"
// currentBuild.result is set, so mail will be sent in next step
 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'rodrigc@localhost', sendToIndividuals: true]) if (err) {
// if previous step failed, we want to exit instead of continuing
 throw err } } echo "currentBuild.result: ${currentBuild.result}" }

It would be nice if the Mailer step printed out a warning in the log if currentBuild.result is null.

--
Craig
Reply all
Reply to author
Forward
0 new messages