Issue
I have a shell script triggered by a jenkins pipeline that detects if files have changed in a folder. I want the script to return 1 or 0 to the pipeline script depending on the changes in the folder. Also I want to read that returned value in the pipeline script, so I can take actions accordingly.
Solution
You can pass the sh
step the returnStdout
or returnStatus
parameters. To my knowledge you can only pass one.
To work around this I would do something like this:
def result = sh script: 'my-command || echo error', returnStdout: true
def error = result.endsWith("error")
error
will only be true if the script returned a non zero exit code.
result
wil contain the output of the script (maybe including the string "error" which can be removed if necessary)
Answered By - smelm
Answer Checked By - Clifford M. (JavaFixing Volunteer)