try/catch in a pipeline?

24 views
Skip to first unread message

Peter Berghold

unread,
Oct 10, 2017, 1:13:04 PM10/10/17
to Jenkins Users
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') 


dandeliondodgeball

unread,
Oct 10, 2017, 1:42:11 PM10/10/17
to Jenkins Users
On this page https://jenkins.io/doc/book/pipeline/jenkinsfile/#syntax there is a Handling Failures section which might help you.  

Jear Krishna

unread,
Oct 10, 2017, 2:30:00 PM10/10/17
to Jenkins Users
you can use post section in pipeline post or you can write try catch in script step.
Reply all
Reply to author
Forward
0 new messages