Mike Caspar added email notification to this example: https://github.com/jenkinsci/pipeline-examples/blob/master/jenkinsfile-examples/nodejs-build-test-deploy-docker-notify/Jenkinsfile
and my script does email notification similar to what you need https://github.com/freebsd/freebsd-ci/blob/master/scripts/build/build-test.groovy#L233 You need to set and check the currentBuild.result value, and do different things based on that. -- Craig On Thu, Jun 23, 2016 at 12:20 AM, Sverre Moe <[email protected]> wrote: > One benefit with sending email in pipeline script is better control of > which error in the pipeline deserves sending email and to whom. > > By adding a try-catch surrounding the code compile I send out email when > it fails. That case the developers get notified only for errors that > concern them. > try { > preInstall() > compileAndBuild() > postInstall() > } catch(e) { > final def RECIPIENTS = emailextrecipients([ > [$class: 'DevelopersRecipientProvider'], > [$class: 'CulpritsRecipientProvider'] > ]) > final def SUBJECT = "${env.JOB_NAME} ${env.BRANCH_NAME} - Build > #${env.BUILD_NUMBER} - FAILED!" > final def CONTENT = "Check console output at ${env.BUILD_URL} to view > the results." > if (RECIPIENTS != null && !RECIPIENTS.isEmpty()) { > mail to: RECIPIENTS, replyTo: "[email protected]", subject: > SUBJECT, body: CONTENT > } else { > mail to: "jenkins-admin", replyTo: "[email protected]", > subject: SUBJECT, body: CONTENT > } > throw e > } > I need to re-throw the exception otherwise the pipeline continues. > > However I still want email to be sent out if there is an error anywhere in > the code. The Jenkins administrators should get an email if the build > scripts fails and has nothing to do with the code. I cannot put a try-catch > everywhere in the code. > > Also how do I send out email on fixed builds? Do I have to do it manually. > Check the previous build, get the recipient list (culprits, developers) > from that build and send a fixed build email message. > > -- > You received this message because you are subscribed to the Google Groups > "Jenkins Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/jenkinsci-users/dbb8fc19-458f-4114-937c-b5136b792562%40googlegroups.com > <https://groups.google.com/d/msgid/jenkinsci-users/dbb8fc19-458f-4114-937c-b5136b792562%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Jenkins Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAG%3DrPVfNi%2B2j_4KmjwB4i5qfCFOs3BguHq9AR%3DRGS%3D%2Bn5MyWRw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
