Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for Not Built #16

Merged
merged 2 commits into from
Jun 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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