[workflow-plugin] Exit code from sh call

59 views
Skip to first unread message

Scott Armit

unread,
Feb 19, 2015, 5:19:45 PM2/19/15
to jenkins...@googlegroups.com
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.

Jesse Glick

unread,
Feb 26, 2015, 11:52:28 AM2/26/15
to jenkins...@googlegroups.com
On Thursday, February 19, 2015 at 5:19:45 PM UTC-5, Scott Armit wrote:
Does anyone know how to do this?

Reply all
Reply to author
Forward
0 new messages