title: Jenkinsfile windows cmd output variable reference
body: <p>I'm pretty new to groovy.In my <code>Jenkinsfile</code> i am trying to store a windows cmd output in a variable, use it in the next command, but nothing seems to be working. This is the closest i got:</p>
  
  <pre><code>    pipeline {
      agent any    
      stages {        
          stage('package-windows') {
              when {
                  expression { isUnix() == false}
              }
              steps {             
                  script {
                  FILENAME = bat(label: 'Get file name', returnStdout: true, script:"dir \".\\archive\\%MY_FOLDER%\\www\\main.*.js\" /s /b")              
                  }
                  bat label: 'replace content', script: "powershell -Command \"(gc \"$FILENAME\") -replace \"https://my-qa.domain.com/api/\", \"https://my-prod.domain.com/api/\" | Out-File \"$FILENAME\"\""
              }
          }
      }
  }
  </code></pre>
  
  <p>When i do <code>ECHO "$FILENAME"</code> this is the output i am getting:</p>
  
  <pre><code>C:\Program Files (x86)\Jenkins\workspace\my-ui&gt;dir ".\archive\55131c0d3c28dc69ce39572eaf2f8585996d9108\main.*.js" /s /b 
  C:\Program Files (x86)\Jenkins\workspace\my-ui\archive\55131c0d3c28dc69ce39572eaf2f8585996d9108\www\main.16aedaf4c6be4e47266d.js
  </code></pre>
  
  <p>All i need is the file name <code>main.16aedaf4c6be4e47266d.js</code> to be used in the next command to modify the contents. But in the next command <code>"$FILENAME"</code> is empty. How can i store the command output in a variable correctly and access in the next commands ?</p>