1
votes

In my Jenkins scripted pipeline, I have a build stage that has the following sh command:

def buildcmd = "./scriptname.sh"+ <paramters>
def status = sh returnStatus: true, script:"""cd /to/some/dir
eval ${buildcmd}
"""
if(status != 0)
{
   error("Failure")
}

After execution, scriptname exits with status 2 and status variable also contains 2 and the job fails. But however the stage result is shown as SUCCESS. I expected both the stage result and build result to be FAILURE.

Can anybody please clarify this.

1

1 Answers

0
votes

returnStatus (optional)

Normally, a script which exits with a nonzero status code will cause the step to fail with an exception. If this option is checked, the return value of the step will instead be the status code. You may then compare it to zero, for example.

Source

If your goal is to simply let the stage fail use returnStatus: false. Unfortunately I can't tell you the difference between a status code and exit code (like mentioned above). The documentation only tells that if you set returnStatus: true the pipeline won't fail on an exit code unequal 0.

You can set the result of the pipeline by yourself (Source):

if(status != 0)
{
   currentBuild.result = 'FAILURE'
}