From 2fc882ee67ae6e50ac1cc5100ca4c4d374fe01dc Mon Sep 17 00:00:00 2001 From: Michal Vala Date: Tue, 5 Sep 2017 14:48:37 +0200 Subject: [PATCH 1/2] ignore idea project files --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 From 54f3bd9f64f9fa32164b05bad4af22a8bbefb79d Mon Sep 17 00:00:00 2001 From: Michal Vala Date: Mon, 18 Jun 2018 13:17:37 +0200 Subject: [PATCH 2/2] added option to set build as Not Built --- .../textfinder/TextFinderPublisher.java | 14 +++++++++- .../TextFinderPublisher/config.jelly | 3 ++ .../help-notBuiltIfFound.html | 3 ++ .../TextFinderPublisherPipelineTest.java | 28 +++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/hudson/plugins/textfinder/TextFinderPublisher/help-notBuiltIfFound.html 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");