title: Jenkins Pipelines: How to use withCredentials() from a shared-variable script
body: <p>I'd like to use a <code>withCredentials()</code> block in a shared-variable ("vars/") script rather than directly in the Jenkins pipeline because this is a lower-level semantic of a particular library, and also may or may not be required depending on the situation. However, <code>withCredentials</code> (or, at least, that signature of it) doesn't appear to be in scope.</p>
  
  <p>script:</p>
  
  <pre><code>def credentials = [
      [$class: 'UsernamePasswordMultiBinding', credentialsId: '6a55c310-aaf9-4822-bf41-5500cd82af4e', passwordVariable: 'GERRIT_PASSWORD', usernameVariable: 'GERRIT_USERNAME'],
      [$class: 'StringBinding', credentialsId: 'SVC_SWREGISTRY_PASSWORD', variable: 'SVC_SWREGISTRY_PASSWORD']
  ]
  
  withCredentials(credentials) {
  // ...
  }
  </code></pre>
  
  <p>Console:</p>
  
  <pre><code>hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: BuildagentInstallAndRun.withCredentials() is applicable for argument types: (java.util.ArrayList, org.jenkinsci.plugins.workflow.cps.CpsClosure2) values: [[[$class:UsernamePasswordMultiBinding, credentialsId:6a55c310-aaf9-4822-bf41-5500cd82af4e, ...], ...], ...]
  </code></pre>
  
  <p>Has anyone had any success with this?</p>