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.
Asked
Active
Viewed 5,970 times
0
-
Refer this https://stackoverflow.com/questions/36547680/how-to-do-i-get-the-output-of-a-shell-command-executed-using-into-a-variable-fro – Sourav Sep 24 '20 at 13:56
1 Answers
3
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)

smelm
- 1,253
- 7
- 14