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

Allow sh to return exit status, stdout and stderr all at once

      Like many of the commenters on -JENKINS-26133- I'd like to be able to capture the exit status and text written to standard out at the same time.

      My current use case is calling git merge --no-edit $branches and if there was an error sending a slack notification with the output. 

      The current workaround is:

      def status = sh(returnStatus: true, script: "git merge --no-edit $branches > merge_output.txt")
      if (status != 0) {
        currentBuild.result = 'FAILED'
        def output = readFile('merge_output.txt').trim()
        slackSend channel: SLACK_CHANNEL, message: "<${env.JOB_URL}|${env.JOB_NAME}> ran into an error merging the PR branches into the ${TARGET_BRANCH} branch:\n```\n${output}\n```\n<${env.BUILD_URL}/console|See the full output>", color: 'warning', tokenCredentialId: 'slack-token'
        error 'Merge conflict'
      }
      sh 'rm merge_output.txt'

      Which works but isn't a great developer experience... It would be great if I could request an object that contained: status, stdout, and stderr.

          [JENKINS-44930] Allow sh to return exit status, stdout and stderr all at once

          andrew morton created issue -
          andrew morton made changes -
          Link New: This issue is related to JENKINS-26133 [ JENKINS-26133 ]
          andrew morton made changes -
          Description Original: Like many of the commenters on JENKINS-26133 I'd like to be able to capture the exit status and text written to standard out at the same time.

          My current use case is calling \{\{git merge --no-edit $branches}} and if there was an error sending a slack notification with the output. 

          The current workaround is:
          {code:java}
          def status = sh(returnStatus: true, script: "git merge --no-edit $branches > merge_output.txt")
          if (status != 0) {
            currentBuild.result = 'FAILED'
            def output = readFile('merge_output.txt').trim()
          }{code}
          Which works but isn't a great developer experience... It would be great if I could request an object that contained: status, stdout, and stderr.
          New: Like many of the commenters on -JENKINS-26133- I'd like to be able to capture the exit status and text written to standard out at the same time.

          My current use case is calling {{git merge --no-edit $branches}} and if there was an error sending a slack notification with the output. 

          The current workaround is:
          {code:java}
          def status = sh(returnStatus: true, script: "git merge --no-edit $branches > merge_output.txt")
          if (status != 0) {
            currentBuild.result = 'FAILED'
            def output = readFile('merge_output.txt').trim()
            slackSend channel: SLACK_CHANNEL, message: "<${env.JOB_URL}|${env.JOB_NAME}> ran into an error merging the PR branches into the ${TARGET_BRANCH} branch:\n```\n${output}\n```\n<${env.BUILD_URL}/console|See the full output>", color: 'warning', tokenCredentialId: 'slack-token'
            error 'Merge conflict'
          }{code}
          Which works but isn't a great developer experience... It would be great if I could request an object that contained: status, stdout, and stderr.
          andrew morton made changes -
          Description Original: Like many of the commenters on -JENKINS-26133- I'd like to be able to capture the exit status and text written to standard out at the same time.

          My current use case is calling {{git merge --no-edit $branches}} and if there was an error sending a slack notification with the output. 

          The current workaround is:
          {code:java}
          def status = sh(returnStatus: true, script: "git merge --no-edit $branches > merge_output.txt")
          if (status != 0) {
            currentBuild.result = 'FAILED'
            def output = readFile('merge_output.txt').trim()
            slackSend channel: SLACK_CHANNEL, message: "<${env.JOB_URL}|${env.JOB_NAME}> ran into an error merging the PR branches into the ${TARGET_BRANCH} branch:\n```\n${output}\n```\n<${env.BUILD_URL}/console|See the full output>", color: 'warning', tokenCredentialId: 'slack-token'
            error 'Merge conflict'
          }{code}
          Which works but isn't a great developer experience... It would be great if I could request an object that contained: status, stdout, and stderr.
          New: Like many of the commenters on --JENKINS-26133-- I'd like to be able to capture the exit status and text written to standard out at the same time.

          My current use case is calling {{git merge --no-edit $branches}} and if there was an error sending a slack notification with the output. 

          The current workaround is:
          {code:java}
          def status = sh(returnStatus: true, script: "git merge --no-edit $branches > merge_output.txt")
          if (status != 0) {
            currentBuild.result = 'FAILED'
            def output = readFile('merge_output.txt').trim()
            slackSend channel: SLACK_CHANNEL, message: "<${env.JOB_URL}|${env.JOB_NAME}> ran into an error merging the PR branches into the ${TARGET_BRANCH} branch:\n```\n${output}\n```\n<${env.BUILD_URL}/console|See the full output>", color: 'warning', tokenCredentialId: 'slack-token'
            error 'Merge conflict'
          }
          sh 'rm merge_output.txt'{code}
          Which works but isn't a great developer experience... It would be great if I could request an object that contained: status, stdout, and stderr.
          Oliver Gondža made changes -
          Priority Original: Minor [ 4 ] New: Major [ 3 ]
          Ed Randall made changes -
          Rank New: Ranked higher
          Jesse Glick made changes -
          Link New: This issue is duplicated by JENKINS-64882 [ JENKINS-64882 ]
          venkateswar rao made changes -
          Rank New: Ranked higher

            Unassigned Unassigned
            drewish andrew morton
            Votes:
            167 Vote for this issue
            Watchers:
            144 Start watching this issue

              Created:
              Updated: