Declarative pipeline: don't send submit / fail notifications if the assembly has been submitted

I am trying to set up pipeline declarative error notifications 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 the build was aborted?

In the "old" pipeline scripts, I caught a FlowInterruptedException to achieve this.

catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
    echo "the job was cancelled or aborted"
    currentBuild.result = 'ABORTED'    
}

      

+3


source to share


1 answer


This was fixed at https://issues.jenkins-ci.org/browse/JENKINS-43339 There was a bug that set currentBuild.result to FAILURE instead of ABORTED.



Make sure to restart jenkins after update.

+4


source







All Articles