Answers: <p>Your string isn't being interpolated at the correct time because it's in single quotes.  Instead it's being passed to the checkout method as an un-interpolated string.  By the time the checkout method interpolates the string, the <code>perf</code> variable is out of scope and so interpretation of this variable falls back to a blank string.  Something like this is what you (probably) want instead:</p>
  
  <pre><code>view: "\"//depot/Software/${perf[i].ID}/...\"" + '//jenkins-${NODE_NAME}-${JOB_NAME}-${EXECUTOR_NUMBER}/...'
  </code></pre>
  
  <p>Note how this concatenates two strings, a double-quoted string and a single-quoted string.  This ensures that each string gets interpolated at different times.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-07-02T12:23:37.380Z
Answers: Worked like a charm, thanks!
Answers: Jack Stevens
Answers: CC BY-SA 4.0
Answers: 2019-06-30T22:03:16.030Z
Answers: 2019-06-30T22:03:16.030Z
Answers: jayhendren
Body: <p>I want to generalize my code so that it can pull from perforce for any files marked with a type "perforce" because some files need to downloaded from the artifactory instead. I want to sub in the variable perf[0].ID into the 'view' parameter so that I can pull different files depending on the ID. However, when I run it, it's passed in as an empty string. Does the checkout plugin not have any support for variables? If there is no support, would having a spec file give me this generality I want? Or do I need to bite the bullet, abandon the checkout plugin and make a batch script?</p>
  
  <p>-->I have an array perf with a type,path,ID, and size field. Here perf[0].ID = "Linak".</p>
  
  <p>stage ('Perforce binaries') {</p>
  
  <pre><code>        steps {
          //can do this "for perforce[].size()" on specified path
            script {
              for (int i = 0; i &lt; perf.size(); i++ ) {
                dir("raw/${perf[i].ID}") {
                  checkout perforce(credential: 'perforce_credentials', populate: autoClean(delete: true, modtime: false, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true, replace: true, tidy: false), workspace: manualSpec(charset: 'none', cleanup: false, name: 'jenkins-${NODE_NAME}-${JOB_NAME}-${EXECUTOR_NUMBER}', pinHost: false, spec: clientSpec(allwrite: false, backup: false, changeView: '', clobber: false, compress: false, line: 'LOCAL', locked: false, modtime: false, rmdir: false, serverID: '', streamName: '', type: 'READONLY', view: '"//depot/Software/${perf[i].ID}/..." //jenkins-${NODE_NAME}-${JOB_NAME}-${EXECUTOR_NUMBER}/...')))
                }
              }
            }
         }
      }
  </code></pre>
  
Tags: <jenkins><environment-variables><versioning>
Title: Jenkins won't substitute variables when trying to check out from perforce
UserDisplayName: Jack Stevens
ThreadText: # Jenkins won't substitute variables when trying to check out from perforce
  
  (Asked by: username_0 on 2019-06-25)
  
  I want to generalize my code so that it can pull from perforce for any files marked with a type "perforce" because some files need to downloaded from the artifactory instead. I want to sub in the variable perf[0].ID into the 'view' parameter so that I can pull different files depending on the ID. However, when I run it, it's passed in as an empty string. Does the checkout plugin not have any support for variables? If there is no support, would having a spec file give me this generality I want? Or do I need to bite the bullet, abandon the checkout plugin and make a batch script?
  
  -->I have an array perf with a type,path,ID, and size field. Here perf[0].ID = "Linak".
  
  stage ('Perforce binaries') {
  
  ```
          steps {
          //can do this "for perforce[].size()" on specified path
            script {
              for (int i = 0; i < perf.size(); i++ ) {
                dir("raw/${perf[i].ID}") {
                  checkout perforce(credential: 'perforce_credentials', populate: autoClean(delete: true, modtime: false, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true, replace: true, tidy: false), workspace: manualSpec(charset: 'none', cleanup: false, name: 'jenkins-${NODE_NAME}-${JOB_NAME}-${EXECUTOR_NUMBER}', pinHost: false, spec: clientSpec(allwrite: false, backup: false, changeView: '', clobber: false, compress: false, line: 'LOCAL', locked: false, modtime: false, rmdir: false, serverID: '', streamName: '', type: 'READONLY', view: '"//depot/Software/${perf[i].ID}/..." //jenkins-${NODE_NAME}-${JOB_NAME}-${EXECUTOR_NUMBER}/...')))
                }
              }
            }
         }
      }
  
  ```
  
  **Tags:** jenkins, environment-variables, versioning
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-06-30. Score: 1
  
  Your string isn't being interpolated at the correct time because it's in single quotes. Instead it's being passed to the checkout method as an un-interpolated string. By the time the checkout method interpolates the string, the `perf` variable is out of scope and so interpretation of this variable falls back to a blank string. Something like this is what you (probably) want instead:
  
  ```
  view: "\"//depot/Software/${perf[i].ID}/...\"" + '//jenkins-${NODE_NAME}-${JOB_NAME}-${EXECUTOR_NUMBER}/...'
  
  ```
  
  Note how this concatenates two strings, a double-quoted string and a single-quoted string. This ensures that each string gets interpolated at different times.
  
  > **Comments:**
  > **username_0**: Worked like a charm, thanks!  
  
  ---
  
  