Jenkins .eachDir() iterate only once
<p>I am trying to do a simple housekeeping pipeline to delete old workspace dirs within Jenkins.</p>

<pre><code>node {
   stage 'Housekeeping stage'
   echo "Deleting all old cell directories, older then ${env.MAXIMUM_CELL_LIVE} days"
   new File("${env.phaser_dir}\\workspace\\").eachDir() { dir -&gt;  
       long diff = new Date().getTime() - dir.lastModified()
       if (diff &gt; env.MAXIMUM_CELL_LIVE.toInteger() * 24 * 60 * 60 * 1000) {
            dir.deleteDir()
        }
    }  
}
</code></pre>

<p>The result is that it iterates only once each time, deleting just one directory.</p>

<p>I have latest version of Pipeline at 2.2. I've also googled there used to be problems like this with <code>.each</code> iterator, but that supposed to be fixed?</p>

<p>Many Thanks
Michal</p>