Post execution of pipeline: send Slack alerts with success and failure

PHOTO EMBED

Tue Aug 10 2021 09:15:28 GMT+0000 (UTC)

Saved by @juferreira #variable #groovy #jenkins #pipeline #post #slack #slackalerts #success #failure

pipeline {
    stages { ... }
    post {
       // only triggered when blue or green sign
       success {
           slackSend(channel: 'alerts-testing', color: 'good', message: ":party_parrot: NOTIFICATION: NEW RELEASE ${newRelease} WILL BE CREATED AUTOMATICALLY :party_parrot:")
       }
       // triggered when red sign
       failure {
           slackSend(channel: 'alerts-testing', color: 'RED', message: ":alarm_clock: NOTIFICATION: NEW RELEASE ${newRelease} WITH SOME FAILURE :alarm_clock:")
       }
       // trigger every-works
       always {
           slackSend ...
       }
    }
}
content_copyCOPY