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

Provide a standardized way of dealing with variables

    XMLWordPrintable

    Details

    • Similar Issues:
    • Epic Link:

      Description

      In order to support a number of use cases, we need a way to define variables that can be accessed across different steps blocks.

      As a talking point, here's what someone was trying to do:

      pipeline {
        agent {
          node label: 'master'
        }
        stages {
          stage('Allocate workspace') {
            steps {
              script {
                def extWorkspace = exwsAllocate 'diskpool1'
              }
            }
          }
          stage('Build') {
            steps {
              parallel(
                "a": {
                  node(label: 'a') {
                    exws (extWorkspace) {
                      sh 'ls -la'
                    }
                  }
                },
                "b": {
                  node(label: 'b') {
                    exws (extWorkspace) {
                      sh 'ls -la'
                    }
                  }
                }
              )
            }
          }
        }
      }
      

        Attachments

          Issue Links

            Activity

            kzantow Keith Zantow created issue -
            jamesdumay James Dumay made changes -
            Field Original Value New Value
            Epic Link JENKINS-36291 [ 172300 ]
            jamesdumay James Dumay made changes -
            Assignee James Dumay [ jamesdumay ]
            kzantow Keith Zantow made changes -
            Assignee Keith Zantow [ kzantow ]
            Hide
            hrmpw Patrick Wolf added a comment -

            Keith Zantow That would work if you define extWorkspace as an environment variable instead of a groovy variable.

            Show
            hrmpw Patrick Wolf added a comment - Keith Zantow That would work if you define extWorkspace as an environment variable instead of a groovy variable.
            Hide
            kzantow Keith Zantow added a comment -

            Patrick Wolf but it's calling `exwsAllocate`, which would have to happen in context of an agent, right?

            Show
            kzantow Keith Zantow added a comment - Patrick Wolf but it's calling `exwsAllocate`, which would have to happen in context of an agent, right?
            Hide
            hrmpw Patrick Wolf added a comment -

            I'm not familiar with that method, Keith Zantow. Does it require a workspace to run on?

            You can always do 

            script {
                      env.extWorkspace = exwsAllocate 'diskpool1'
                    }
            

            assuming, of course, that it returns a string.

            Show
            hrmpw Patrick Wolf added a comment - I'm not familiar with that method, Keith Zantow . Does it require a workspace to run on? You can always do  script { env.extWorkspace = exwsAllocate 'diskpool1' } assuming, of course, that it returns a string.
            jamesdumay James Dumay made changes -
            Epic Link JENKINS-36291 [ 172300 ] JENKINS-45422 [ 183590 ]
            abayer Andrew Bayer made changes -
            Link This issue duplicates JENKINS-44376 [ JENKINS-44376 ]
            abayer Andrew Bayer made changes -
            Resolution Duplicate [ 3 ]
            Status Open [ 1 ] Fixed but Unreleased [ 10203 ]

              People

              Assignee:
              kzantow Keith Zantow
              Reporter:
              kzantow Keith Zantow
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: