O'Reilly logo

Continuous Integration, Delivery, and Deployment by Sander Rossel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Build failure

No matter how well you write your code, your build will fail once in a while (and probably more often), so it is a good idea to send an email when this happens. The declarative pipeline has a post node that lets you act on a certain build status, for example, failure. The post block can be placed in the top node of your pipeline or in a stage block (that way, we could have omitted the try-finally block earlier). The post conditions are always, changed, failure, success, and unstable. We are going to use failure and send an email:

pipeline {  agent any  [...]  stages {    [...]  }  post {    failure {      mail body: """FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':           Check console output at ${env.BUILD_URL}""", subject: """FAILED: Job '${env.JOB_NAME} ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required