Jenkins won't substitute variables when trying to check out from perforce 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 &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}/...')))
              }
            }
          }
       }
    }
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.