I am trying to list files in the workspace in Jenkins Pipeline so that I can use them to create related parallel tasks.
While I could just use sh ls > files and read this, I need File objects that I can filter on with more complex logic. In fact, Files.listFiles(FileFilter) would be ideal.
However, I cannot get the list of files at all. Firstly, I had to resort to some strange things to just find out the current directory of work for the assembly:
sh 'pwd > workspace' workspace = readFile('workspace').trim()
Now I call this to get a list of files:
@NonCPS def getFiles(String baseDir) { Arrays.asList(new File(baseDir).listFiles()) }
And get NPE on asList , which means that after reading javadoc that new File(baseDir) does not exist (or is not a directory).
I mark it with @NonCPS because it is needed to close groovy on the pipeline, which I would prefer to use over the full java <1.8 syntax.
source share