#215 email notifications will now only occur on changes to the status
Merged by ralph. Opened by jmolet.
jmolet/greenwave improved-email  into  master

Download 215.patch

This PR sets the e-mailer to only notify if the build result has changed. In lieu of threaded emails, this simply reduces the amount of jenkins spam sent to the list/owner. Testing this is interesting since you have to break something and then fix it somewhere in the pipeline steps above. I did this using something like the following pipeline:

try { // massive try{} catch{} around the entire build for failure notifications
node('master') {
    stage('Invoke Flake8') {
    // change this to false to fail the job <<<<<
    sh 'true'  
    }
}
} catch (e) {
    currentBuild.result = 'FAILURE'
    throw e
} finally {
        def currentResult = currentBuild.result ?: 'SUCCESS'
        def previousResult = currentBuild.previousBuild?.result
        def SUBJECT = ''
        def BODY = "${env.BUILD_URL}"
        if (previousResult == 'FAILURE' && currentResult == 'SUCCESS') {
            SUBJECT = "Jenkins job ${env.JOB_NAME} #${env.BUILD_NUMBER} fixed."
        }
        else if (previousResult == 'SUCCESS' && currentResult == 'FAILURE' ) {
            SUBJECT = "Jenkins job ${env.JOB_NAME} #${env.BUILD_NUMBER} failed."
        }
        if (SUBJECT != '') {
            emailext to: ownership.job.primaryOwnerEmail,
                     subject: SUBJECT,
                     body: BODY
        }
}

Running this multiple times and changing the sh step's return value you can see the pattern of emails on status changes.

:+1: looks like a nice improvement.

:+1:

@jmolet, can you merge this and submit the same change to https://pagure.io/waiverdb and https://pagure.io/freshmaker ?

rebased onto 377ab103b67a889037704fa03daf2ea7ee23dd7e

@ralph I've rebased this PR on master, but I don't have write access to this upstream repo. I'll open PRs against those other projects though.

Ack, thanks!

Pull-Request has been merged by ralph

Metadata