Currently sh has no meaningful return value, and throws an exception if the exit status is not zero. Would be nice to have an option to have it return the exit code (zero or not) as an integer value:

      def r = sh script: 'someCommand', returnStatus: true
      

      Current workaround:

      sh 'someCommand; echo $? > status'
      def r = readFile('status').trim()
      

      Or to have it return its standard output (akin to shell backticks):

      def lines = sh(script: 'dumpStuff.sh', returnStdout: true).split("\r?\n")
      

      Workaround:

      sh 'dumpStuff.sh > result'
      def lines = readFile('result').split("\r?\n")
      

      Or to have it take something on standard input:

      sh script: 'loadStuff.sh', stdin: someText
      

      Workaround:

      writeFile file: 'input', text: someText
      sh 'loadStuff.sh < input'
      

      Probably requires some API changes in durable-task.

          [JENKINS-26133] Shell script taking/returning output/status

          tridnguyen not Jenkins, but a plugin. See https://github.com/jenkinsci/workflow-durable-task-step-plugin/commit/94ad105034de65a614d6e7d3d0504b4d1a6a761e

          So you need the Pipeline: Nodes and Processes plugin in version >= 2.4

          Baptiste Mathus added a comment - tridnguyen not Jenkins, but a plugin. See https://github.com/jenkinsci/workflow-durable-task-step-plugin/commit/94ad105034de65a614d6e7d3d0504b4d1a6a761e So you need the Pipeline: Nodes and Processes plugin in version >= 2.4

          Its returning result or output? what if I want both? why not always return something like ScriptResultObject that has both status and the output in it?

          then you would only need a flag if you want to propagate status to jenkins, or you could have customised propagation by parsing output.

          Jakub Pawlinski added a comment - Its returning result or output? what if I want both? why not always return something like ScriptResultObject that has both status and the output in it? then you would only need a flag if you want to propagate status to jenkins, or you could have customised propagation by parsing output.

          Michael Rose added a comment -

          +1 for Jakub proposed improvement.

          Michael Rose added a comment - +1 for Jakub proposed improvement.

          Jesse Glick added a comment -

          quas mrose etc. I have no plans to implement such an RFE (see the repeated explanations of the alternative you can use today), but if you want to file it anyway, it should be a separate linked issue (and please use votes, not comments, to register your personal priority to reduce noise to watchers).

          Jesse Glick added a comment - quas mrose etc. I have no plans to implement such an RFE (see the repeated explanations of the alternative you can use today), but if you want to file it anyway, it should be a separate linked issue (and please use votes, not comments, to register your personal priority to reduce noise to watchers).

          ben ji added a comment -

          I am using a docker push command in a pipeline:  sh "docker push 10.10.174.28/dev/vote:0.$BUILD_NUMBER"

          I need to provide a password using standard input to the command - (there doesn't seem to be any other way to pass in the data in an automated environment)

          I don't understand how to apply the workaround to my case:
          writeFile file: 'input', text: someText
          sh 'loadStuff.sh < input'
          Any help would be greatly appreciated.

           

           

          ben ji added a comment - I am using a docker push command in a pipeline:  sh "docker push 10.10.174.28/dev/vote:0.$BUILD_NUMBER" I need to provide a password using standard input to the command - (there doesn't seem to be any other way to pass in the data in an automated environment) I don't understand how to apply the workaround to my case: writeFile file: 'input', text: someText sh 'loadStuff.sh < input' Any help would be greatly appreciated.    

          David Schott added a comment -

          Hi benji2006, there are other ways to provide a password besides stdin.

          Check out this example Jenkinsfile (apologies for weird formatting) and note the usage of Credentials & 'environment' in the "Build & Push Docker Image" stage.

          David Schott added a comment - Hi benji2006 , there are other ways to provide a password besides stdin. Check out this example Jenkinsfile (apologies for weird formatting) and note the usage of Credentials & 'environment' in the "Build & Push Docker Image" stage.

          ben ji added a comment - - edited

          Hi shott85,

          this isn't a regular docker log in - in this particular scenario using Notary, it looks like the only way to pass in the required content is via stdin - there are no env variables that work - see the second update to this bug report:

           

          https://forums.docker.com/t/cannot-get-trust-delegation-to-work-notary-v0-3-0-solved/14370

          SECOND UPDATE:

          Looks as if I can supply the passphrase on standard input – seems to be working now.

           

           

          I can get the command to work outside Jenkins using 

          echo "delegationpass" | docker push .....

          and need to emulate that in my pipeline script

           

          ben ji added a comment - - edited Hi shott85 , this isn't a regular docker log in - in this particular scenario using Notary, it looks like the only way to pass in the required content is via stdin - there are no env variables that work - see the second update to this bug report:   https://forums.docker.com/t/cannot-get-trust-delegation-to-work-notary-v0-3-0-solved/14370 SECOND UPDATE: Looks as if I can supply the passphrase on standard input – seems to be working now.     I can get the command to work outside Jenkins using  echo "delegationpass" | docker push ..... and need to emulate that in my pipeline script  

          Jesse Glick added a comment -

          benji2006 please do not use JIRA as a help forum. There is a users’ list and other places to ask for help using Jenkins.

          Jesse Glick added a comment - benji2006 please do not use JIRA as a help forum. There is a users’ list and other places to ask for help using Jenkins.

          andrew morton added a comment -

          I went ahead and created https://issues.jenkins-ci.org/browse/JENKINS-44930 to focus on returning the exit status and standard output at the same time. So I hope all the folks who commented asking for this feature will go up vote that

          andrew morton added a comment - I went ahead and created https://issues.jenkins-ci.org/browse/JENKINS-44930  to focus on returning the exit status and standard output at the same time. So I hope all the folks who commented asking for this feature will go up vote that

          Vision Xu added a comment -

           

          Code:

          def output = sh( 
              script: """cd ${component_root_path} && JAVA_HOME=${JAVA_HOME} mvn dependency:list -Dsort=true""", 
              returnStdout: true
          )
          

           

           

          But Get no output.

          [Pipeline] echo
          [12-22 22:18:28] output: 
          

          Vision Xu added a comment -   Code: def output = sh( script: """cd ${component_root_path} && JAVA_HOME=${JAVA_HOME} mvn dependency:list -Dsort= true " "", returnStdout: true )     But Get no output. [Pipeline] echo [12-22 22:18:28] output:

            jglick Jesse Glick
            jglick Jesse Glick
            Votes:
            50 Vote for this issue
            Watchers:
            65 Start watching this issue

              Created:
              Updated:
              Resolved: