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'
}