diff --git a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/FindFilesStep.java b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/FindFilesStep.java index 2dd54381..38513c38 100644 --- a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/FindFilesStep.java +++ b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/FindFilesStep.java @@ -47,6 +47,7 @@ */ public class FindFilesStep extends Step { private String glob; + private String excludes; @DataBoundConstructor public FindFilesStep() { @@ -80,6 +81,21 @@ public void setGlob(String glob) { this.glob = glob; } + /** + * Pattern of files to excludes in the list. This is useful for large + * directory structure (i.e npm-modules) + * + * @return the excludes pattern + */ + public String getExcludes() { + return excludes; + } + + @DataBoundSetter + public void setExcludes(String excludes) { + this.excludes = excludes; + } + @Extension public static class DescriptorImpl extends StepDescriptor { diff --git a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/FindFilesStepExecution.java b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/FindFilesStepExecution.java index deabafb3..c5d8b6ca 100644 --- a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/FindFilesStepExecution.java +++ b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/FindFilesStepExecution.java @@ -60,7 +60,7 @@ protected FileWrapper[] run() throws Exception { if (StringUtils.isBlank(step.getGlob())) { list = ws.list(); } else { - list = Arrays.asList(ws.list(step.getGlob())); + list = Arrays.asList(ws.list(step.getGlob(), step.getExcludes())); } FileWrapper[] res = new FileWrapper[list.size()]; for(int i = 0; i < list.size(); i++) { diff --git a/src/main/resources/org/jenkinsci/plugins/pipeline/utility/steps/fs/FindFilesStep/config.groovy b/src/main/resources/org/jenkinsci/plugins/pipeline/utility/steps/fs/FindFilesStep/config.groovy index face5803..8ff8a9ad 100644 --- a/src/main/resources/org/jenkinsci/plugins/pipeline/utility/steps/fs/FindFilesStep/config.groovy +++ b/src/main/resources/org/jenkinsci/plugins/pipeline/utility/steps/fs/FindFilesStep/config.groovy @@ -27,4 +27,8 @@ def f = namespace(lib.FormTagLib) as lib.FormTagLib f.entry(field: 'glob', title: _('Glob')) { f.textbox() +} + +f.entry(field: 'exclusions', title: _('Exclusions')) { + f.textbox() } \ No newline at end of file diff --git a/src/main/resources/org/jenkinsci/plugins/pipeline/utility/steps/fs/FindFilesStep/help-exclusions.html b/src/main/resources/org/jenkinsci/plugins/pipeline/utility/steps/fs/FindFilesStep/help-exclusions.html new file mode 100644 index 00000000..bd50761e --- /dev/null +++ b/src/main/resources/org/jenkinsci/plugins/pipeline/utility/steps/fs/FindFilesStep/help-exclusions.html @@ -0,0 +1,28 @@ + + +
+ Ant style pattern + of file paths that should be excluded. +
\ No newline at end of file diff --git a/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/FindFilesStepTest.java b/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/FindFilesStepTest.java index a1586a08..1693a896 100644 --- a/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/FindFilesStepTest.java +++ b/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/FindFilesStepTest.java @@ -151,4 +151,31 @@ public void listSome() throws Exception { j.assertLogNotContains("F: b/11.txt", run); j.assertLogNotContains("F: b/12.txt", run); } + + @Test + public void listSomeWithExclusions() throws Exception { + String flow = CODE.replace("%TESTCODE%", + "def files = findFiles(glob: '**/*.txt', excludes: 'b/*.txt,**/aba/*.txt')\n" + + "echo \"${files.length} files\"\n" + + "for(int i = 0; i < files.length; i++) {\n" + + " echo \"F: ${files[i].path.replace('\\\\', '/')}\"\n" + + "}" + ); + p.setDefinition(new CpsFlowDefinition(flow, true)); + WorkflowRun run = j.assertBuildStatusSuccess(p.scheduleBuild2(0)); + + j.assertLogContains("8 files", run); + j.assertLogContains("F: 1.txt", run); + j.assertLogContains("F: 2.txt", run); + j.assertLogContains("F: a/3.txt", run); + j.assertLogContains("F: a/4.txt", run); + j.assertLogContains("F: a/aa/5.txt", run); + j.assertLogContains("F: a/aa/6.txt", run); + j.assertLogContains("F: a/ab/7.txt", run); + j.assertLogContains("F: a/ab/8.txt", run); + j.assertLogNotContains("F: a/ab/aba/9.txt", run); + j.assertLogNotContains("F: a/ab/aba/10.txt", run); + j.assertLogNotContains("F: b/11.txt", run); + j.assertLogNotContains("F: b/12.txt", run); + } } \ No newline at end of file