diff --git a/.gitignore b/.gitignore index 3f29f5d..c7355bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /target/ -/work/ \ No newline at end of file +/work/ +.idea/ +*.iml diff --git a/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java b/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java index dbd53d2..d4986f5 100644 --- a/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java +++ b/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java @@ -50,6 +50,7 @@ public class TextFinderPublisher extends Recorder implements Serializable, Simpl public final String regexp; public boolean succeedIfFound; public boolean unstableIfFound; + public boolean notBuiltIfFound; /** True to also scan the whole console output */ public boolean alsoCheckConsoleOutput; @@ -94,6 +95,11 @@ public void setUnstableIfFound(boolean unstableIfFound) { this.unstableIfFound = unstableIfFound; } + @DataBoundSetter + public void setNotBuiltIfFound(boolean notBuiltIfFound) { + this.notBuiltIfFound = notBuiltIfFound; + } + @DataBoundSetter public void setAlsoCheckConsoleOutput(boolean alsoCheckConsoleOutput) { this.alsoCheckConsoleOutput = alsoCheckConsoleOutput; @@ -137,7 +143,13 @@ private void findText(Run run, FilePath workspace, TaskListener listener) } if (foundText != succeedIfFound) { - run.setResult(unstableIfFound ? Result.UNSTABLE : Result.FAILURE); + final Result finalResult; + if (notBuiltIfFound) { + finalResult = Result.NOT_BUILT; + } else { + finalResult = unstableIfFound ? Result.UNSTABLE : Result.FAILURE; + } + run.setResult(finalResult); } } catch (AbortException e) { // no test file found diff --git a/src/main/resources/hudson/plugins/textfinder/TextFinderPublisher/config.jelly b/src/main/resources/hudson/plugins/textfinder/TextFinderPublisher/config.jelly index 2c79b0d..41debca 100644 --- a/src/main/resources/hudson/plugins/textfinder/TextFinderPublisher/config.jelly +++ b/src/main/resources/hudson/plugins/textfinder/TextFinderPublisher/config.jelly @@ -16,4 +16,7 @@ + + + diff --git a/src/main/resources/hudson/plugins/textfinder/TextFinderPublisher/help-notBuiltIfFound.html b/src/main/resources/hudson/plugins/textfinder/TextFinderPublisher/help-notBuiltIfFound.html new file mode 100644 index 0000000..8ce01f8 --- /dev/null +++ b/src/main/resources/hudson/plugins/textfinder/TextFinderPublisher/help-notBuiltIfFound.html @@ -0,0 +1,3 @@ +
+ Use this option to set build as Not Built. +
\ No newline at end of file diff --git a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java index ad14937..648abf3 100644 --- a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java +++ b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java @@ -91,6 +91,20 @@ public void unstableIfFoundInFile() throws Exception { rule.assertBuildStatus(Result.UNSTABLE, build); } + @Test + public void notBuiltIfFoundInFile() throws Exception { + WorkflowJob project = rule.createProject(WorkflowJob.class, "pipeline"); + project.setDefinition( + new CpsFlowDefinition( + "node {writeFile file: 'out.txt', text: 'foobar'}\n" + + "node {findText regexp: 'foobar', fileSet: 'out.txt', notBuiltIfFound: true}\n")); + WorkflowRun build = project.scheduleBuild2(0).get(); + rule.waitForCompletion(build); + rule.assertLogContains("Checking foobar", build); + assertLogContainsMatch(new File(getWorkspace(build), "out.txt"), UNIQUE_TEXT, build, false); + rule.assertBuildStatus(Result.NOT_BUILT, build); + } + @Test public void notFoundInFile() throws Exception { WorkflowJob project = rule.createProject(WorkflowJob.class, "pipeline"); @@ -146,6 +160,20 @@ public void unstableIfFoundInConsole() throws Exception { rule.assertBuildStatus(Result.UNSTABLE, build); } + @Test + public void notBuiltIfFoundInConsole() throws Exception { + WorkflowJob project = rule.createProject(WorkflowJob.class, "pipeline"); + project.setDefinition( + new CpsFlowDefinition( + "node {isUnix() ? sh('echo foobar') : bat(\"prompt \\$G\\r\\necho foobar\")}\n" + + "node {findText regexp: 'foobar', notBuiltIfFound: true, alsoCheckConsoleOutput: true}\n")); + WorkflowRun build = project.scheduleBuild2(0).get(); + rule.waitForCompletion(build); + rule.assertLogContains("Checking console output", build); + assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); + rule.assertBuildStatus(Result.NOT_BUILT, build); + } + @Test public void notFoundInConsole() throws Exception { WorkflowJob project = rule.createProject(WorkflowJob.class, "pipeline");