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

Ability to set output of a step to environment variable(s)

      When using steps like input that capture data from a user, it makes sense to be able to set the resultant values to environment variables.

      This could be generalised to other steps that return values (perhaps as maps).

      In pipeline-model, the way data is passed around is via (environment) variables as there are no local variables, so the ability to set environment variables to the output is required.

          [JENKINS-38394] Ability to set output of a step to environment variable(s)

          Michael Neale created issue -
          Andrew Bayer made changes -
          Link New: This issue is duplicated by JENKINS-38332 [ JENKINS-38332 ]
          Jesse Glick made changes -
          Link New: This issue depends on JENKINS-34101 [ JENKINS-34101 ]

          Jesse Glick added a comment -

          Currently input returns typed objects, so JENKINS-34101 would be needed to get these in a form amenable to passing to withEnv.

          Jesse Glick added a comment - Currently input returns typed objects, so JENKINS-34101 would be needed to get these in a form amenable to passing to withEnv .

          Michael Neale added a comment -

          hrmpw what do you think about a pipeline-model specific "captureInput" step - which wraps input and grabs its stuff as env vars? (may be easier than the changes needed to input?)

          Michael Neale added a comment - hrmpw what do you think about a pipeline-model specific "captureInput" step - which wraps input and grabs its stuff as env vars? (may be easier than the changes needed to input?)

          Patrick Wolf added a comment -

          I think a generalized method to set the output of a step in an environment variable is a decent hack but it feels like a temporary workaround until the step is supported natively. Otherwise, a quick script block works just as well.

          For input I think we need a more elegant solution. I agree with jglick that input might require a more specialized setup in declarative. I think we should look into including an input section of the per-stage configuration like notifications.

          Patrick Wolf added a comment - I think a generalized method to set the output of a step in an environment variable is a decent hack but it feels like a temporary workaround until the step is supported natively. Otherwise, a quick script block works just as well. For input I think we need a more elegant solution. I agree with jglick that input might require a more specialized setup in declarative. I think we should look into including an input section of the per-stage configuration like notifications.
          James Dumay made changes -
          Epic Link New: JENKINS-45422 [ 183590 ]

          Andrew Bayer added a comment -

          So in JENKINS-48379, we're adding a stage-level input section, which runs before the agent and when, and will put any parameters it's given into the environment. I think this does the trick.

          Andrew Bayer added a comment - So in JENKINS-48379 , we're adding a stage -level input section, which runs before the agent and when , and will put any parameters it's given into the environment. I think this does the trick.
          Andrew Bayer made changes -
          Link New: This issue duplicates JENKINS-48379 [ JENKINS-48379 ]
          Andrew Bayer made changes -
          Resolution New: Duplicate [ 3 ]
          Status Original: Open [ 1 ] New: Resolved [ 5 ]

            abayer Andrew Bayer
            michaelneale Michael Neale
            Votes:
            1 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: