title: enviroment variables on jenkins pipeline for user and password
body: <p>I´m quite new on using groovy for jenkins pipeline. I have a pipeline that is already running performing some steps like running unitest, sonnarqube anaysis etc. One of the steps is to upload artifact to artifactory using curl -u. I don´t want to show user and pass on output script, so I´m using credential plug in In which I stored user and password and has the ID. But I don´t know how to pass that to the sh command using variables. This is what I have now in that step using withCredentials . </p>
  
  <pre><code>stage ('Upload war to Artifactory') {
              withCredentials([usernamePassword(credentialsId: '7c9e8186-1f16-4920-837b-b571ea88a7e8', usernameVariable: 'willy11', passwordVariable: 'hello123')])
  sh "sudo curl -u ${willy11}:{$hello123} -T $warPath 'https://artifactory.xxxxx.com:443/artifactory/Platform/$warFile'" 
  </code></pre>
  
  <p>I don´t know how to pass or define values of <strong>usernameVariable</strong> and <strong>passwordVariable</strong> to use on the curl command. The way it is now, I get on output script:</p>
  
  <pre><code>java.lang.IllegalStateException: **There is no body to invoke**
  at org.jenkinsci.plugins.workflow.cps.CpsStepContext.newBodyInvoker(CpsStepContext.java:283)
  at org.jenkinsci.plugins.workflow.cps.CpsStepContext.newBodyInvoker(CpsStepContext.java:95)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/vGt7L.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vGt7L.jpg" alt="enter image description here"></a></p>
  
  <p>How can I achieve this? the credential plug in,  I read that supposedly puts *** on the output of the script, is this how this work? should I declare "will11" and "hello123"  elsewere and use as env variables? </p>
  
  <p>Thank you.</p>
  
  <pre><code>def call(body) {
  
  def config = [:]
  body.resolveStrategy = Closure.DELEGATE_FIRST
  body.delegate = config
  body()
  
  def artifactName = 'extractor'
  def artifactExt = '.war'
  def artifactVersion = '0.0.1'
  
  def buildPath = 'target/'
  def warFile = artifactName + '-' + artifactVersion + artifactExt
  def warPath = buildPath + warFile
  def warNoVersion = artifactName + artifactExt
  
  def deployPath = '/var/lib/tomcat8/webapps/'
  def deployFile = deployPath + warNoVersion
  
  node {
      // Clean workspace before doing anything
      //deleteDir()
  
      try {
  
          stage ('Code Checkout') {
              git branch: 'master',
                  credentialsId: 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
                  url: 'ssh://git@bitbucket.org/xxxxxxx/xxxxxxxctor'
          }
  
  
  stage ('Configure Application') {
              configFileProvider([configFile(fileId: config.confiFileId, variable: 'CONFIG_FILE_PATH')]) {
                  sh 'cp $CONFIG_FILE_PATH resources/config.properties'
              }
              sh "echo 'job_name: $JOB_NAME' &gt; WebContent/version.txt"
              sh "echo 'job_number: $BUILD_NUMBER' &gt;&gt; WebContent/version.txt"
          }
  
          stage ('Run Unitests') {
              sh 'mvn test'
          }
  
          /*stage ('SonarQube analysis') {
            withSonarQubeEnv('xxxxxxxxxxxxxxxx) {
              sh 'mvn sonar:sonar'
            }  
          }*/
  
          stage ('Compile and Build WAR') {
              sh 'mvn clean compile war:war'
          }
  
          stage ('Upload war to Artifactory') {
              withCredentials([usernamePassword(credentialsId: '7c9e8186-1f16-4920-837b-b571ea88a7e8', usernameVariable: 'USER', passwordVariable: 'PASSWORD')])
              sh "sudo curl -u ${USER}:{$PASSWORD} -T $warPath 'https://artifactory.xxxxxxx.com:443/artifactory/Platform/$warFile'" 
  
          }
  
  
  
  
      } catch (err) {
          notifyBuild('FAILURE', config.slackChannel)
          throw err
      }
  }
  </code></pre>