try/catch in a pipeline?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

try/catch in a pipeline?

Peter Berghold
I've noticed some "non-deterministic behavior" in my first few pipelines and I was wondering if there i some sort of try/catch structure I could use to catch errors.  It would sort of look like this: 

try { 
      sh 'some_unix_command'
} catch { 
     send_mail('Step foo failed on some_unix_command') 


--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAArvnv0LVdGBP3yfGT2t7tFEMDa8fDykZqjt19xHKnGOXZz3sg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: try/catch in a pipeline?

dandeliondodgeball
On this page https://jenkins.io/doc/book/pipeline/jenkinsfile/#syntax there is a Handling Failures section which might help you.  

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/85db0f81-a28e-4b24-9f34-f02f42668e6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: try/catch in a pipeline?

Jear Krishna
In reply to this post by Peter Berghold
you can use post section in pipeline post or you can write try catch in script step.

On Tuesday, October 10, 2017 at 10:43:04 PM UTC+5:30, Peter Berghold wrote:
I've noticed some "non-deterministic behavior" in my first few pipelines and I was wondering if there i some sort of try/catch structure I could use to catch errors.  It would sort of look like this: 

try { 
      sh 'some_unix_command'
} catch { 
     send_mail('Step foo failed on some_unix_command') 


--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/d7d8d8c2-380f-46f1-90c5-d4fc626b0283%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.