Hi. I've searched quite a bit without an answer.
Using the new workflow plugin (Groovy CPS DSL) is it possible to retrieve the exit code from a 'sh' call? If this were a straight bash call via "Execute shell script" in a Freestyle job, I would just read $? and flow from there. For instance, perhaps I want to take a different action when my return value is 0, or 1, or 2874 (made up obviously), and from there decide if the job succeeded or failed.
I can use a 'try/catch' to know that a step failed, but I cannot figure out how to access this exit code. Certainly the worfklow plugin has the exit code becasuse it displays this at the end of the flow. Basically I want to (pseudocode):
<snip>
def result = 0
try {
sh "<some command>"
} catch(e) {
if (e.exitCode == 3) {
// this code is ok, do something interesting
} else if (e.exitCode == 4) {
// this is bad, set the result
result += 1
}
}
return result
<snip>
Therefore, my logic could decide whether or not the workflow failed, not simply whether or not the 'sh' call returned non-zero. Does anyone know how to do this?
Thanks a lot.