List files on the workspace on a Jenkins Pipeline
<p>I'm trying to list files in the workspace in a Jenkins Pipeline, so that I can use that to produce appropriate parallel tasks.</p>

<p>While I could simply use <code>sh ls &gt; files</code> and read that, I want <code>File</code> objects which I can filter further with more complex logic. In fact, <code>Files.listFiles(FileFilter)</code> would be ideal.</p>

<p>However, I can't get the list of files at all. First, I had to resort to some weird stuff to simply find out the current work directory for the build:</p>

<pre><code>sh 'pwd &gt; workspace'
workspace = readFile('workspace').trim()
</code></pre>

<p>Now I call this to retrieve the list of files:</p>

<pre><code>@NonCPS
def getFiles(String baseDir) {
    Arrays.asList(new File(baseDir).listFiles())
}
</code></pre>

<p>And get a NPE on <code>asList</code>, which means, by my read of the javadoc, that <code>new File(baseDir)</code> does not exist (or is not a directory).</p>

<p>I'm tagging it <code>@NonCPS</code> because it's required for groovy closures on Pipeline, which I'd really prefer to use over full java &lt;1.8 syntax.</p>