If you use currentBuild.currentResult (was added a few months ago IIRC) you get 
a value that will never be null. 

From: jer...@bodycad.com
Sent: 04 December 2017 17:06
To: Jenkins Users
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: 
't...@test.dev', replyTo: 't...@test.dev', 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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/dfdf3042-8b26-4f83-b43f-a17b8142a4a3%40googlegroups.com.
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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/5a266724.43af500a.705b8.e595%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to