title: Access files on a node slave from Jenkins master using Groovy
body: <p>I am using the Jenkins Build Flow plugin to achieve parallelization. The Groovy DSL does certain file operations. Even though the option <code>Restrict where this project can be run</code> is set to run the job on a specific slave, the DSL runs on master. This is not intended.</p>
  
  <p>Could someone tell me how I can restrict the DSL to run on the specified slave? Even if there is a way we can access the slave file system via the DSL, that should work.</p>
  
  <p>In general, how can we access files on a node slave from Jenkins master using Groovy?</p>
  
  <pre><code>def fp = new hudson.FilePath(build.workspace.channel, "/srv/jenkins/workspace/myworkspace_on_slave_node")
  assert fp.exists()      // returns true :)
  
  def ant = new AntBuilder()
  
  if (fp != null) {
    def scanner = ant.fileScanner {    // fails here :(, says /srv/jenkins/workspace/myworkspace_on_slave_node not found
      // grab ALL files requested to be run
      fileset(dir: "$fp", includes: "**/*.java")
    }
  
    // now lets iterate over - print - and count test files
    int numFiles = 0
    for (f in scanner) {
      println("Found file $f")    
      numFiles++
    }
    println("Total files $numFiles")
  }
  </code></pre>
  
  <p>The workspace is there on the slave node, but the above code is failing when I am trying to open the FileSet to the remote FilePath.</p>