title: Groovy string interpolation in jenkins pipeline - mixing credentials and constants
body: <p>Struggling with a part of my jenkinsfile which requires mixed credentials and defined variables passed into a function.</p>
  <p>Function looks like this:</p>
  <pre><code>platformList.each { platform -&gt; 
      stage(&quot;Build ${platform}&quot;) {
          withCredentials([usernamePassword(credentialsId: 'XXX-XXX-XX', passwordVariable: 'unity_password', usernameVariable: 'unity_username')]) {
              sh label: &quot;Build App&quot;, script: '${WORKSPACE}/ci/build_app.sh build_app ${platform} ${deployment} $unity_username $unity_password'
          }
      }
  }
  </code></pre>
  <p>I'm trying to adhere to the advice around string interpolation as discussed here: <a href="https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#string-interpolation" rel="noreferrer">https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#string-interpolation</a></p>
  <p>However, I don't seem to be able to mix the interpolated credentials with single-quotes, and the derived <code>${platform}</code> variable as defined in the each loop.</p>
  <p><code>platformList</code> is an array containing 1+ strings. It is generated like this:</p>
  <pre><code>script {
      if (params['windows'] == true) {
          platformList.add(&quot;windows&quot;)
      }
      if (params['osx'] == true) {
          platformList.add(&quot;osx&quot;)
      }
      ...
  }
  </code></pre>
  <p>If I run this script as-is, the <code>${platform}</code> variable will be passed as a blank string to the <code>sh</code> call.</p>
  <p>If I double-quote the <code>sh</code> call it works fine, but then I get the warning about insecure credentials passed via interpolation.</p>
  <p>The <code>${deployment}</code> variable, which is a string param defined as part of the execution of the job, parses without issue, so I assume this is a problem related to the <code>each</code> loop specifically.</p>