Hi,

So after reading this:
https://github.com/jenkinsci/workflow-plugin/blob/master/basic-steps/src/main/resources/org/jenkinsci/plugins/workflow/steps/CatchErrorStep/help.html

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




On Mon, Jan 25, 2016 at 4:42 PM, Craig Rodrigues <rodr...@freebsd.org>
wrote:

> This build which failed:
> https://jenkins.freebsd.org/job/FreeBSD_HEAD/74/flowGraphTable/
>
> uses the same script:
>
>
> https://github.com/freebsd/freebsd-ci/blob/master/scripts/build/build-test.groovy
> <https://github.com/freebsd/freebsd-ci/blob/master/scripts/build/build-test.groovy#L190>
>
> 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
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/CAG%3DrPVezhg0g%3DxNxo44eLWfvNd2jS_j3_xmR3zPc0dUF6KSK-A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to