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

Shell script taking/returning output/status

    XMLWordPrintable

Details

    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

            visxu 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: 
            
            visxu 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:
            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

            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
            jglick 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.

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

             

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

            shott85 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.

            People

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

              Dates

                Created:
                Updated:
                Resolved: