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]) } }
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}" }