Skip to content

Commit

Permalink
Merge pull request #16 from sparkoo/notbuilt
Browse files Browse the repository at this point in the history
added support for Not Built
  • Loading branch information
basil committed Jun 18, 2018
2 parents e8cda29 + 54f3bd9 commit 436cef6
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/target/
/work/
/work/
.idea/
*.iml
14 changes: 13 additions & 1 deletion src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@
<f:entry field="unstableIfFound" title="${%Unstable if found}">
<f:checkbox/>
</f:entry>
<f:entry field="notBuiltIfFound" title="${%Not Built if found}">
<f:checkbox/>
</f:entry>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
Use this option to set build as Not Built.
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 436cef6

Please sign in to comment.