Quantcast
Channel: Active questions tagged bash - DevOps Stack Exchange
Viewing all articles
Browse latest Browse all 47

Why does Jenkins Pipeline script returnStatus value not match status examined in shell?

0
0

This is my little newbie Groovy script, trying to cobble together a very beginner understanding of Jenkins Pipelines:

node { stage("hello") {  def var = "val"  echo "${var}"  def stdout = sh( script: 'pwd', returnStdout: true ).trim()  echo "${stdout}"  def ret_status = sh( script: 'cd subdir', returnStatus: true )  echo "${ret_status}" }}

The output is:

Started by user unknown or anonymousRunning in Durability level: MAX_SURVIVABILITY[Pipeline] Start of Pipeline[Pipeline] nodeRunning on Jenkins in /home/user/workspace/newbie_dont_know_what_hes_doin[Pipeline] {[Pipeline] stage[Pipeline] { (hello)[Pipeline] echoval[Pipeline] sh+ pwd[Pipeline] echo/home/user/workspace/newbie_dont_know_what_hes_doin[Pipeline] sh+ cd subdir/home/user/workspace/newbie_dont_know_what_hes_doin@tmp/durable-2fa119e0/script.sh: 1: cd: can't cd to subdir[Pipeline] echo2[Pipeline] }[Pipeline] // stage[Pipeline] }[Pipeline] // node[Pipeline] End of PipelineFinished: SUCCESS

The failure to cd subdir is intentional -- to demonstrate the mechanics of capturing shell stdout and status.

Why does the failed cd subdir report a returnStatus of 2 when cding to nonexistent directories in bash returns status-code 1? The Groovy documentation I have as reference says sh runs a Bourne shell script.

$ echo $SHELL/bin/bash$ cd subdir-bash: cd: subdir: No such file or directory$ echo $?1$

Viewing all articles
Browse latest Browse all 47

Latest Images

Trending Articles





Latest Images