Jenkins – Shell script catch error or error code

Spread the love

 

By default, shell can break Jenkins pipeline if exit code different from 0. But ideally need to create handler for catch error and provide actions based on error code from script.

For catch error code for shell script need to call sh with argument returnStatus: true 

Example:

def script = "ls -lh"
def statusCode = sh(returnStatus: true, script: script)

Leave a Reply