I'm trying to set up notifications on declarative pipeline failures as described here:
https://jenkins.io/doc/pipeline/tour/post/
post {
failure {
emailext (
subject: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: """<p>FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
<p>Check console output at "<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>"</p>""",
recipientProviders: [[$class: 'CulpritsRecipientProvider']]
)
}
}
}
Is there a way to not send emails if a build was aborted?
In "old" scripted pipelines I caught the FlowInterruptedException to achieve this.
catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
echo "the job was cancelled or aborted"
currentBuild.result = 'ABORTED'
}
This has been fixed by https://issues.jenkins-ci.org/browse/JENKINS-43339 There was a bug which set the currentBuild.result to FAILURE instead of ABORTED.
Make sure to restart jenkins after the update.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With