Stop sending email notifications for superseded builds

This commit is contained in:
Christian Beikov 2022-08-31 08:31:23 +02:00
parent 3352486633
commit 8a806ef261
1 changed files with 16 additions and 12 deletions

28
Jenkinsfile vendored
View File

@ -316,23 +316,27 @@ void handleNotifications(currentBuild, buildEnv) {
<p>Check console output at <a href='${env.BUILD_URL}'>${env.BUILD_URL}</a> to view the results.</p>""" <p>Check console output at <a href='${env.BUILD_URL}'>${env.BUILD_URL}</a> to view the results.</p>"""
} }
} }
else if ( currentResult == 'FAILURE' ) { else if (currentBuild.rawBuild.getActions(jenkins.model.InterruptedBuildAction.class).isEmpty()) {
if ( previousResult != null && previousResult == "FAILURE" ) { // If there are interrupted build actions, this means the build was cancelled, probably superseded
subject = "${env.JOB_NAME} - Build ${env.BUILD_NUMBER} - Still failing" // Thanks to https://issues.jenkins.io/browse/JENKINS-43339 for the "hack" to determine this
body = """<p>${env.JOB_NAME} - Build ${env.BUILD_NUMBER} - Still failing:</p> if ( currentResult == 'FAILURE' ) {
<p>Check console output at <a href='${env.BUILD_URL}'>${env.BUILD_URL}</a> to view the results.</p>""" if ( previousResult != null && previousResult == "FAILURE" ) {
subject = "${env.JOB_NAME} - Build ${env.BUILD_NUMBER} - Still failing"
body = """<p>${env.JOB_NAME} - Build ${env.BUILD_NUMBER} - Still failing:</p>
<p>Check console output at <a href='${env.BUILD_URL}'>${env.BUILD_URL}</a> to view the results.</p>"""
}
else {
subject = "${env.JOB_NAME} - Build ${env.BUILD_NUMBER} - Failure"
body = """<p>${env.JOB_NAME} - Build ${env.BUILD_NUMBER} - Failure:</p>
<p>Check console output at <a href='${env.BUILD_URL}'>${env.BUILD_URL}</a> to view the results.</p>"""
}
} }
else { else {
subject = "${env.JOB_NAME} - Build ${env.BUILD_NUMBER} - Failure" subject = "${env.JOB_NAME} - Build ${env.BUILD_NUMBER} - ${currentResult}"
body = """<p>${env.JOB_NAME} - Build ${env.BUILD_NUMBER} - Failure:</p> body = """<p>${env.JOB_NAME} - Build ${env.BUILD_NUMBER} - ${currentResult}:</p>
<p>Check console output at <a href='${env.BUILD_URL}'>${env.BUILD_URL}</a> to view the results.</p>""" <p>Check console output at <a href='${env.BUILD_URL}'>${env.BUILD_URL}</a> to view the results.</p>"""
} }
} }
else {
subject = "${env.JOB_NAME} - Build ${env.BUILD_NUMBER} - ${currentResult}"
body = """<p>${env.JOB_NAME} - Build ${env.BUILD_NUMBER} - ${currentResult}:</p>
<p>Check console output at <a href='${env.BUILD_URL}'>${env.BUILD_URL}</a> to view the results.</p>"""
}
emailext( emailext(
subject: subject, subject: subject,