Quantcast

Pipeline jobs: How are return codes handled?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Pipeline jobs: How are return codes handled?

David Aldrich-2

Hi

 

In a conventional Jenkins job, my understanding is that the job will fail if the last command of a shell build step indicates an error.

 

I am now experimenting with pipeline jobs and have something like:

 

node {

    stage('Checkout') {<snip>}

 

    sh returnStatus: true, script: '''cd software

                                      make cleanall

                                      make '''

}

 

I am not sure what is happening here.

 

1)      Will the same rule apply that the job will fail if the last command of the sh step fails?

2)      What is ‘returnStatus: true, script’ doing?

 

Best regards

 

David

 

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/ebb7c18a1b2740258af7e7e91deffce8%40EUX13SRV1.EU.NEC.COM.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Pipeline jobs: How are return codes handled?

Ramanathan Muthaiah
On Friday, April 21, 2017 at 3:22:49 PM UTC+5:30, David Aldrich wrote:

Hi

 

In a conventional Jenkins job, my understanding is that the job will fail if the last command of a shell build step indicates an error.

 

I am now experimenting with pipeline jobs and have something like:

 

node {

    stage('Checkout') {<snip>}

 

    sh returnStatus: true, script: '''cd software

                                      make cleanall

                                      make '''

}

 

I am not sure what is happening here.

 

1)      Will the same rule apply that the job will fail if the last command of the sh step fails?

2)      What is ‘returnStatus: true, script’ doing?


Regd item 2), returnStatus will return the execution completion status of commands enclosed within "script: "

It can be either 127 (if the command is not found) or 1 for failed valid command or 0 for valid command that has been executed successfully.

Refer to these links for more info:

https://issues.jenkins-ci.org/browse/JENKINS-26133

https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#code-sh-code-shell-script

http://stackoverflow.com/questions/36956977/how-to-execute-a-command-in-a-jenkins-2-0-pipeline-job-and-then-return-the-stdou

http://stackoverflow.com/questions/36547680/how-to-do-i-get-the-output-of-a-shell-command-executed-using-into-a-variable-fro

https://support.cloudbees.com/hc/en-us/articles/218554077-How-to-set-current-build-result-in-Pipeline

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/befed8e7-cc85-4fb7-a585-bb7e31d41cb5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Pipeline jobs: How are return codes handled?

David Aldrich-2

Thanks for your reply but I am still confused.  Looking at:

 

https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#code-sh-code-shell-script

 

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.

 

So if I specify that option I get the status code, but will Jenkins fail the pipeline if the code is non-zero or do I have to do that myself?

 

If I don’t specify that option I will get an exception on a failure.  Will that fail the job neatly or will I get an exception trace?

 

From: Ramanathan Muthaiah [mailto:[hidden email]]
Sent: 21 April 2017 11:05
To: Jenkins Users <[hidden email]>
Cc: David Aldrich <[hidden email]>
Subject: Re: Pipeline jobs: How are return codes handled?

 

On Friday, April 21, 2017 at 3:22:49 PM UTC+5:30, David Aldrich wrote:

Hi

 

In a conventional Jenkins job, my understanding is that the job will fail if the last command of a shell build step indicates an error.

 

I am now experimenting with pipeline jobs and have something like:

 

node {

    stage('Checkout') {<snip>}

 

    sh returnStatus: true, script: '''cd software

                                      make cleanall

                                      make '''

}

 

I am not sure what is happening here.

 

1)      Will the same rule apply that the job will fail if the last command of the sh step fails?

2)      What is ‘returnStatus: true, script’ doing?

 

Click here to report this email as spam.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/20a2d132608c4d7bac0918129029e45c%40EUX13SRV1.EU.NEC.COM.
For more options, visit https://groups.google.com/d/optout.
Loading...