On 5 December 2017 at 09:30, Daniel Butler <[email protected]> wrote:
> If you use currentBuild.currentResult (was added a few months ago IIRC) > you get a value that will never be null. > but it may not be completely correct. https://gitbox.apache.org/repos/asf?p=maven-jenkins-lib.git;a=blob;f=vars/asfMavenTlpStdBuild.groovy;h=b03cd5e5c79ad26302f9e16d5af543aee96f426c;hb=HEAD#l97 is my best attempt at determining the different build results... I am not completely happy that it catches all cases correctly though > > > *From: *[email protected] > *Sent: *04 December 2017 17:06 > *To: *Jenkins Users <[email protected]> > *Subject: *Re: Translation between declaritive pipleline and groovy > pipeline > > > > You need to wrap your groovy code into a try/catch/finally block and check > the current build result ( I also give you some hint when things are not > yet filled) > > try > { > } > catch(any) > { > println('Error occurred during build:'); > > println(any.toString()); > > println('Marking build as FAILURE because of this'); > > currentBuild.result = 'FAILURE' > > throw any //rethrow exception to prevent the build from proceeding > > } > finally > { > if(!currentBuild.result) > > { > > currentBuild.result = 'SUCCESS' > > println("Current build result is undefined, setting it as > ${currentBuild.result}") > > } > > // send email > emailext body: 'my email body', subject: 'email subject', to: > '[email protected]', replyTo: '[email protected]', mimeType: 'text/html'; > } > > > > > > -- > 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/dfdf3042-8b26-4f83-b43f-a17b8142a4a3%40googlegroups. > com > <https://groups.google.com/d/msgid/jenkinsci-users/dfdf3042-8b26-4f83-b43f-a17b8142a4a3%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/5a266724.43af500a.705b8.e595%40mx.google.com > <https://groups.google.com/d/msgid/jenkinsci-users/5a266724.43af500a.705b8.e595%40mx.google.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/CA%2BnPnMyvDBXRWXRLgyV_647kqUzZNSxaVJQ0-xYhMdekP1grHw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
