3
votes

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 &QUOT;<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>&QUOT;</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'    
}
1
This should have been fixed by issues.jenkins-ci.org/browse/JENKINS-43339 There was a bug which set the currentBuild.result to FAILURE instead of ABORTED But I still get the error mail.Roman Pickl
worked after restarting jenkins (again?)Roman Pickl

1 Answers

5
votes

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.