title: Jenkins Declarative Pipeline, run groovy script on slave agent
body: <p>I have a Jenkins declarative pipeline I have been running on the Jenkins master and it works fine. However, now that I have moved to trying to execute this on a slave node, the groovy scripts which are called in the pipeline can not access the files in the workspace. </p>
  
  <p>My jenkinsfile looks like this...</p>
  
  <pre><code>pipeline {
  
  agent {
    label {
          label "windows"
          customWorkspace "WS-${env.BRANCH_NAME}"
    }
  }
  
  stages {
    stage('InitialSetup') {
     steps {
       "${env.WORKSPACE}/JenkinsScripts/myScript.groovy"
      }
    }
  }
  </code></pre>
  
  <p>I can see on the slave that it is creating the workspace, doing the checkout from git, and executing the script correctly. However, if something in the script try's to interact with the files in the workspace it fails. </p>
  
  <p>If I have something simple like this...</p>
  
  <pre><code>def updateFile(String filename) {
    echo env.NODE_NAME
    filename = "${env.WORKSPACE}/path/to/file"
    def myFile = new File(filename)
    &lt;do other things with the file&gt;
  }
  </code></pre>
  
  <p>...it says it can not find the file specified. It gives me the path it is looking for and I can confirm the file exists, and that the code runs when just building on the master. </p>
  
  <p>Why can the script not find the files this way when in can just running on the master node? I added the "echo env.NODE_NAME" command into my groovy file and it says the script is executing on the correct node.</p>
  
  <p>Thanks.</p>