0

This blog post describes very well how to setup notifications for failed jobs within the Pipeline DSL.

Unfortunately, this approach has a severe drawback: There is no (email) notification at all if the SCM is not reachable because Jenkins is not able to checkout the Jenkinsfile. Does anyone know a solution or workaround for that so that I get notified if a Pipeline Job fails because of SCM issues while checking out the Jenkinsfile (or also in case of syntax errors within the Jenkinsfile)?

1 Answers1

-1

If you have the Email-ext plugin installed you can call it from your pipeline script.

You can use the snippet generator that comes with pipeline plugin (available at $JENKINS_URL/pipeline-syntax). Select the plugin and configure it as you would used to do in a post build step.

Put the generated snippet in your pipeline. You might want to wrap it in a try {..} finally {..}

emailext attachLog: true, 
    body: 'Oops', 
    recipientProviders: [[ $class: 'DevelopersRecipientProvider']], 
    subject: 'Failing tests', to: 'someone@example.com'

The beuaty about this pipeline-syntax is that it will dynamically add the plugins you install (so if you used to use a different notification plugin, it should show up here).

You can also take a look at this documentation where they give some examples as well.

This is a similar question

Community
  • 1
  • 1
Rik
  • 3,647
  • 2
  • 25
  • 34
  • Thanks, but the question was how to get notified when the SCM is not reachable or if there is a syntax error within the Jenkinsfile. This solution does not help here because if the SCM is not available, Jenkins will not be able to checkout the notification code you posted and therefore will do no notification at all. It also does not help in within the second case that there is a syntax error in the Jenkinsfile because the Groovy code will not be executable in this case. – Patrick Fink Dec 09 '16 at 11:49
  • Aha, I see. Misunderstood the question then. Unfortunately I don't know. You can maybe create another job that only sends an email. Configure it to always run after the other job even if it fails. Don't know, but you might be able to fetch the log from the upstream and include it in the mail – Rik Dec 09 '16 at 18:49