Skip to content

Notifications

Andrew Bayer edited this page Nov 17, 2016 · 9 revisions

email, HipChat, slack, IRC

The post section of a pipeline can define both where to send a notification, and on what event. Because notifications are steps, making use of Jenkins plugins to send them is doable. In this example, using email:

    post {
        success {
            mail to:"me@example.com", subject:"SUCCESS: ${currentBuild.fullDisplayName}", body: "Yay, we passed."
        }
        failure {
            mail to:"me@example.com", subject:"FAILURE: ${currentBuild.fullDisplayName}", body: "Boo, we failed."
        }
        unstable {
            mail to:"me@example.com", subject:"UNSTABLE: ${currentBuild.fullDisplayName}", body: "Huh, we're unstable."
        }
        changed {
            mail to:"me@example.com", subject:"CHANGED: ${currentBuild.fullDisplayName}", body: "Wow, our status changed!"
        }
    }

There is also HipChat, Slack, IRC and more (even Yo has a notifier).

(Seriously: https://github.com/jenkinsci/notify-yo-plugin - it won't work in current form with pipeline, however, and I am not even sure if Yo still exists as an app).

You can put notifications as top-level declarations (inside pipeline) or on a per stage basis. For example:

pipeline {
    agent any
    stages {
      stage('build') {

        post {
           success {
             mail to:"me@example.com", subject:"SUCCESS: ${currentBuild.fullDisplayName}", body: "Yay."
           }
        }

        steps {
          sh 'make install'
        }


      }
    }
}