Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-26133

Shell script taking/returning output/status

    Details

    • Similar Issues:

      Description

      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.

        Attachments

          Issue Links

            Activity

            Hide
            benji2006 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.

             

             

            Show
            benji2006 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.    
            Hide
            shott85 David Schott added a comment -

            Hi ben ji, 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.

            Show
            shott85 David Schott added a comment - Hi ben ji , 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.
            Hide
            benji2006 ben ji added a comment - - edited

            Hi David Schott,

            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

             

            Show
            benji2006 ben ji added a comment - - edited Hi David Schott , 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  
            Hide
            jglick Jesse Glick added a comment -

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

            Show
            jglick Jesse Glick added a comment - ben ji please do not use JIRA as a help forum. There is a users’ list and other places to ask for help using Jenkins.
            Hide
            drewish 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

            Show
            drewish 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

              People

              • Assignee:
                jglick Jesse Glick
                Reporter:
                jglick Jesse Glick
              • Votes:
                50 Vote for this issue
                Watchers:
                64 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: