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

Assign variable from shell output using declarative pipeline

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      Currently, we can capture the output of a shell step inside of a script block, but have no way to do that in clean declarative pipeline syntax. For example, this post on StackOverflow must instead be:

      // Git committer email
      script {
        GIT_COMMIT_EMAIL = sh (
          script: 'git --no-pager show -s --format=\'%ae\'',
          returnStdout: true
        ).trim()
      }
      echo "Git committer email: ${GIT_COMMIT_EMAIL}"
      

      It also doesn't work to wrap it in a declarative environment block, though that may perhaps be a reasonable place to extend the syntax.

        Attachments

          Issue Links

            Activity

            Hide
            dnusbaum Devin Nusbaum added a comment - - edited

            There might be an existing issue to track this kind of thing already, but IIUC it is somewhat by design (CC Andrew Bayer). In your example at least you could move your echo into the script you run, but perhaps that is not your real use case.

            Show
            dnusbaum Devin Nusbaum added a comment - - edited There might be an existing issue to track this kind of thing already, but IIUC it is somewhat by design (CC Andrew Bayer ). In your example at least you could move your echo into the script you run, but perhaps that is not your real use case.
            Hide
            abayer Andrew Bayer added a comment -

            Yeah, this is one aspect of JENKINS-44376.

            Show
            abayer Andrew Bayer added a comment - Yeah, this is one aspect of JENKINS-44376 .

              People

              • Assignee:
                Unassigned
                Reporter:
                bryceman Bryce Schober
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: