Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<relativePath />
</parent>
<artifactId>junit</artifactId>
<version>1.24-SNAPSHOT</version>
<version>1.25</version>
<packaging>hpi</packaging>
<name>JUnit Plugin</name>
<description>Allows JUnit-format test results to be published.</description>
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/hudson/tasks/junit/JUnitParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ public class JUnitParser extends TestResultParser {

private final boolean keepLongStdio;
private final boolean allowEmptyResults;
private final boolean makeUnstable;

/** TODO TestResultParser.all does not seem to ever be called so why must this be an Extension? */
@Deprecated
public JUnitParser() {
this(false, false);
this(false, false, true);
}

/**
Expand All @@ -66,16 +67,20 @@ public JUnitParser() {
public JUnitParser(boolean keepLongStdio) {
this.keepLongStdio = keepLongStdio;
this.allowEmptyResults = false;
this.makeUnstable = true;

}

/**
* @param keepLongStdio if true, retain a suite's complete stdout/stderr even if this is huge and the suite passed
* @param allowEmptyResults if true, empty results are allowed
* @param makeUnstable if true, build will be Unstable if there are any failed test cases
* @since 1.10
*/
public JUnitParser(boolean keepLongStdio, boolean allowEmptyResults) {
public JUnitParser(boolean keepLongStdio, boolean allowEmptyResults, boolean makeUnstable) {
this.keepLongStdio = keepLongStdio;
this.allowEmptyResults = allowEmptyResults;
this.makeUnstable = makeUnstable;
}

@Override
Expand Down Expand Up @@ -112,7 +117,7 @@ public TestResult parseResult(String testResultLocations, Run<?,?> build, Pipeli
// also get code that deals with testDataPublishers from JUnitResultArchiver.perform

return workspace.act(new ParseResultCallable(testResultLocations, buildTime, timeOnMaster, keepLongStdio,
allowEmptyResults, pipelineTestDetails));
allowEmptyResults, makeUnstable, pipelineTestDetails));
}

private static final class ParseResultCallable extends MasterToSlaveFileCallable<TestResult> {
Expand All @@ -121,16 +126,19 @@ private static final class ParseResultCallable extends MasterToSlaveFileCallable
private final long nowMaster;
private final boolean keepLongStdio;
private final boolean allowEmptyResults;
private final boolean makeUnstable;
private final PipelineTestDetails pipelineTestDetails;

private ParseResultCallable(String testResults, long buildTime, long nowMaster,
boolean keepLongStdio, boolean allowEmptyResults,
boolean makeUnstable,
PipelineTestDetails pipelineTestDetails) {
this.buildTime = buildTime;
this.testResults = testResults;
this.nowMaster = nowMaster;
this.keepLongStdio = keepLongStdio;
this.allowEmptyResults = allowEmptyResults;
this.makeUnstable = makeUnstable;
this.pipelineTestDetails = pipelineTestDetails;
}

Expand Down
25 changes: 23 additions & 2 deletions src/main/java/hudson/tasks/junit/JUnitResultArchiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public class JUnitResultArchiver extends Recorder implements SimpleBuildStep, JU
* If true, don't throw exception on missing test results or no files found.
*/
private boolean allowEmptyResults;
private boolean makeUnstable;

@DataBoundConstructor
public JUnitResultArchiver(String testResults) {
Expand Down Expand Up @@ -119,6 +120,7 @@ public JUnitResultArchiver(
setTestDataPublishers(testDataPublishers == null ? Collections.<TestDataPublisher>emptyList() : testDataPublishers);
setHealthScaleFactor(healthScaleFactor);
setAllowEmptyResults(false);
setMakeUnstable(true);
}

private TestResult parse(String expandedTestResults, Run<?,?> run, @Nonnull FilePath workspace, Launcher launcher, TaskListener listener)
Expand All @@ -132,7 +134,7 @@ private static TestResult parse(@Nonnull JUnitTask task, PipelineTestDetails pip
String expandedTestResults, Run<?,?> run, @Nonnull FilePath workspace,
Launcher launcher, TaskListener listener)
throws IOException, InterruptedException {
return new JUnitParser(task.isKeepLongStdio(), task.isAllowEmptyResults())
return new JUnitParser(task.isKeepLongStdio(), task.isAllowEmptyResults(), task.isMakeUnstable())
.parseResult(expandedTestResults, run, pipelineTestDetails, workspace, launcher, listener);
}

Expand All @@ -154,6 +156,7 @@ public void perform(Run build, FilePath workspace, Launcher launcher,

if (action != null && action.getResult().getFailCount() > 0)
build.setResult(Result.UNSTABLE);
listener.getLogger().println(Messages.JUnitResultArchiver_ChangeState("UNSTABLE"));
}

public static TestResultAction parseAndAttach(@Nonnull JUnitTask task, PipelineTestDetails pipelineTestDetails,
Expand Down Expand Up @@ -192,6 +195,12 @@ public static TestResultAction parseAndAttach(@Nonnull JUnitTask task, PipelineT
// most likely a configuration error in the job - e.g. false pattern to match the JUnit result files
throw new AbortException(Messages.JUnitResultArchiver_ResultIsEmpty());
}

if (!task.isMakeUnstable()) {
// Change the buils state to Unstable if there are any failed test cases
listener.getLogger().println(Messages.JUnitResultArchiver_ResultIsEmpty());
return null;
}

// TODO: Move into JUnitParser [BUG 3123310]
if (task.getTestDataPublishers() != null) {
Expand Down Expand Up @@ -285,11 +294,23 @@ public boolean isKeepLongStdio() {
public boolean isAllowEmptyResults() {
return allowEmptyResults;
}

@DataBoundSetter public final void setAllowEmptyResults(boolean allowEmptyResults) {
this.allowEmptyResults = allowEmptyResults;
}

/**
*
* @return the makeUnstable
*/
public boolean isMakeUnstable() {
return makeUnstable;
}


@DataBoundSetter public final void setMakeUnstable(boolean makeUnstable) {
this.makeUnstable = makeUnstable;
}

private static final long serialVersionUID = 1L;

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/hudson/tasks/junit/JUnitTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public interface JUnitTask {
boolean isKeepLongStdio();

boolean isAllowEmptyResults();

boolean isMakeUnstable();
}
14 changes: 14 additions & 0 deletions src/main/java/hudson/tasks/junit/pipeline/JUnitResultsStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class JUnitResultsStep extends Step implements JUnitTask {
* If true, don't throw exception on missing test results or no files found.
*/
private boolean allowEmptyResults;
private boolean makeUnstable;

@DataBoundConstructor
public JUnitResultsStep(String testResults) {
Expand Down Expand Up @@ -119,6 +120,19 @@ public boolean isAllowEmptyResults() {
this.allowEmptyResults = allowEmptyResults;
}


/**
*
* @return the makeUnstable
*/
public boolean isMakeUnstable() {
return makeUnstable;
}

@DataBoundSetter public final void setMakeUnstable(boolean makeUnstable) {
this.makeUnstable = makeUnstable;
}

@Override
public StepExecution start(StepContext context) throws Exception {
return new JUnitResultsStepExecution(this, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@ THE SOFTWARE.
<f:entry title="${%Allow empty results}" field="allowEmptyResults">
<f:checkbox default="false" title="${%Do not fail the build on empty test results}"/>
</f:entry>
<f:entry title="${%Make the build UNSTABLE}" field="makeUnstable">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix it. Thanks

<f:checkbox default="true" title="${%Change the build state to UNSTABLE if there are any failed Unit tests}"/>
</f:entry>
</j:jelly>
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ JUnitParser.TestResultLocationMessage=JUnit xml files:
JUnitResultArchiver.DisplayName=Publish JUnit test result report
JUnitResultArchiver.NoTestReportFound=No test report files were found. Configuration error?
JUnitResultArchiver.Recording=Recording test results
JUnitResultArchiver.ChangeState=Changing build state to {0} because there are failed tests
JUnitResultArchiver.ResultIsEmpty=None of the test reports contained any result
JUnitResultArchiver.HealthScaleFactorAnalysis={0}% failing tests scores as {1}% health. {2}% failing tests scores as {3}% health

Expand Down