title: Dynamic variable in Jenkins pipeline with groovy method variable
body: <p>I have a Jenkinsfile in Groovy for a declarative pipeline and two created Jenkins variables with names OCP_TOKEN_VALUE_ONE and OCP_TOKEN_VALUE_TWO and the corresponding values. The problem comes when I try to pass a method variable and use it in an sh command.</p>
  
  <p>I have the next code:</p>
  
  <pre><code>private def deployToOpenShift(projectProps, environment, openshiftNamespaceGroupToken) {  
    sh """/opt/ose/oc login ${OCP_URL} --token=${openshiftNamespaceGroupToken} --namespace=${projectProps.namespace}-${environment}"""
  }
  </code></pre>
  
  <p>The problem is, the method <code>deployToOpenShift</code> has in the <code>openshiftNamespaceGroupToken</code> variable, a value that is the name of variable that has been set in Jenkins. It needs to be dynamic and the problem is that Jenkins don't resolve the Jenkins variable value, just the one passed as String, I mean, the result is:</p>
  
  <blockquote>
    <p>--token=OCP_TOKEN_VALUE_ONE</p>
  </blockquote>
  
  <p>If I put in the code</p>
  
  <pre><code>private def deployToOpenShift(projectProps, environment, openshiftNamespaceGroupToken) {  
    sh """/opt/ose/oc login ${OCP_URL} --token=${OCP_TOKEN_VALUE_ONE} --namespace=${projectProps.namespace}-${environment}"""
  }
  </code></pre>
  
  <p>works perfect but is not dynamic that is the point of the method variable. I have tried with the """ stuff as you can see, but not working.</p>
  
  <p>Any extra idea?</p>
  
  <p><strong>Edited</strong> with the code that calls the method:</p>
  
  <pre><code>...
  projectProps = readProperties file: './gradle.properties'
  openShiftTokenByGroup = 'OCP_TOKEN_' + projectProps.namespace.toUpperCase()
  
  ...
  
  stage ('Deploy-Dev') {
    agent any
    steps {
      milestone ordinal : 10, label: "Deploy-Dev Milestone"
      deployToOpenShift(projectProps, 'dev', openShiftTokenByGroup)
    }
  }
  </code></pre>