I am working on a Jenkins custom Plugin, where I need to list all valid FilePaths: sub-Directories and child files, excluding some temporary files like .git,.npm,.cache etc, the full list is included in below code sample:
String excludes = "node_modules/**/*,**/node_modules/**/*,.git/**,.npm*/**,**/.npm*/**,**/.nvm*/**,**/cronus/**,**/.cache/**,**/npmtmp/**,**/.tmp/**";
FilePath[] validFileAndFolderPaths = workspace.list("**/*", excludes);
The above code is giving me all of the files in the workspace FilePath, but not the sub-directories.
There is a method for listing all sub-directories hudson.FilePath#listDirectories, but that doesn't support exclusion list.
Any help on how to achieve this requirement?
You can't use
hudson.FilePath#listDirectorieswith a exclude/include patterns. Hence you will have to implement your own method to get the directories supporting Ant pattern matching. Here is a sample code.Dependency
Java Code
Calling the method