From 223cd6498078b5fa4e0c77fc7ff5a9f35232ca4a Mon Sep 17 00:00:00 2001 From: Nguoi An Phu Date: Thu, 21 Dec 2017 10:46:44 +0000 Subject: [PATCH 01/14] Adding a new option to make the build UNSTABLE or not --- pom.xml | 2 +- .../java/hudson/tasks/junit/JUnitParser.java | 14 ++++++++--- .../tasks/junit/JUnitResultArchiver.java | 25 +++++++++++++++++-- .../java/hudson/tasks/junit/JUnitTask.java | 2 ++ .../junit/pipeline/JUnitResultsStep.java | 14 +++++++++++ .../junit/JUnitResultArchiver/config.jelly | 3 +++ .../hudson/tasks/junit/Messages.properties | 1 + 7 files changed, 55 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 3fe9cfbe8..9cfac2ae2 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ junit - 1.24-SNAPSHOT + 1.25 hpi JUnit Plugin Allows JUnit-format test results to be published. diff --git a/src/main/java/hudson/tasks/junit/JUnitParser.java b/src/main/java/hudson/tasks/junit/JUnitParser.java index 80f45ca37..b9923cb4b 100644 --- a/src/main/java/hudson/tasks/junit/JUnitParser.java +++ b/src/main/java/hudson/tasks/junit/JUnitParser.java @@ -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); } /** @@ -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 @@ -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 { @@ -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; } diff --git a/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java b/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java index ba4189ecc..beb69f23e 100644 --- a/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java +++ b/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java @@ -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) { @@ -119,6 +120,7 @@ public JUnitResultArchiver( setTestDataPublishers(testDataPublishers == null ? Collections.emptyList() : testDataPublishers); setHealthScaleFactor(healthScaleFactor); setAllowEmptyResults(false); + setMakeUnstable(true); } private TestResult parse(String expandedTestResults, Run run, @Nonnull FilePath workspace, Launcher launcher, TaskListener listener) @@ -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); } @@ -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, @@ -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) { @@ -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; diff --git a/src/main/java/hudson/tasks/junit/JUnitTask.java b/src/main/java/hudson/tasks/junit/JUnitTask.java index 05590444d..8972d49e4 100644 --- a/src/main/java/hudson/tasks/junit/JUnitTask.java +++ b/src/main/java/hudson/tasks/junit/JUnitTask.java @@ -12,4 +12,6 @@ public interface JUnitTask { boolean isKeepLongStdio(); boolean isAllowEmptyResults(); + + boolean isMakeUnstable(); } diff --git a/src/main/java/hudson/tasks/junit/pipeline/JUnitResultsStep.java b/src/main/java/hudson/tasks/junit/pipeline/JUnitResultsStep.java index a730d840b..0aaf7d325 100644 --- a/src/main/java/hudson/tasks/junit/pipeline/JUnitResultsStep.java +++ b/src/main/java/hudson/tasks/junit/pipeline/JUnitResultsStep.java @@ -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) { @@ -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); diff --git a/src/main/resources/hudson/tasks/junit/JUnitResultArchiver/config.jelly b/src/main/resources/hudson/tasks/junit/JUnitResultArchiver/config.jelly index b7cc707f9..4649e92de 100644 --- a/src/main/resources/hudson/tasks/junit/JUnitResultArchiver/config.jelly +++ b/src/main/resources/hudson/tasks/junit/JUnitResultArchiver/config.jelly @@ -46,4 +46,7 @@ THE SOFTWARE. + + + diff --git a/src/main/resources/hudson/tasks/junit/Messages.properties b/src/main/resources/hudson/tasks/junit/Messages.properties index ee534eae2..8019c23bc 100644 --- a/src/main/resources/hudson/tasks/junit/Messages.properties +++ b/src/main/resources/hudson/tasks/junit/Messages.properties @@ -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 From 8ad30d3c0fa786053045de2ba0ef5422daa8c1f0 Mon Sep 17 00:00:00 2001 From: Nguoi An Phu Date: Fri, 22 Dec 2017 06:21:36 +0000 Subject: [PATCH 02/14] Adding a new option to make the build UNSTABLE or not - fixed code review comments --- pom.xml | 4 ++-- .../java/hudson/tasks/junit/JUnitParser.java | 17 +++++++++++++++-- .../tasks/junit/JUnitResultArchiverTest.java | 1 + 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 9cfac2ae2..d50559838 100644 --- a/pom.xml +++ b/pom.xml @@ -7,14 +7,14 @@ junit - 1.25 + 1.25-SNAPSHOT hpi JUnit Plugin Allows JUnit-format test results to be published. http://wiki.jenkins-ci.org/display/JENKINS/JUnit+Plugin 2.7.3 - 7 + 8 false 2.37 2.14 diff --git a/src/main/java/hudson/tasks/junit/JUnitParser.java b/src/main/java/hudson/tasks/junit/JUnitParser.java index b9923cb4b..d29896612 100644 --- a/src/main/java/hudson/tasks/junit/JUnitParser.java +++ b/src/main/java/hudson/tasks/junit/JUnitParser.java @@ -53,12 +53,14 @@ public class JUnitParser extends TestResultParser { 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, true); } - + + /** * @param keepLongStdio if true, retain a suite's complete stdout/stderr even if this is huge and the suite passed * @since 1.358 @@ -68,8 +70,19 @@ 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 + * @since 1.10 + */ + public JUnitParser(boolean keepLongStdio, boolean allowEmptyResults) { + this.keepLongStdio = keepLongStdio; + this.allowEmptyResults = allowEmptyResults; + this.makeUnstable = true; + } /** * @param keepLongStdio if true, retain a suite's complete stdout/stderr even if this is huge and the suite passed diff --git a/src/test/java/hudson/tasks/junit/JUnitResultArchiverTest.java b/src/test/java/hudson/tasks/junit/JUnitResultArchiverTest.java index fae242a1a..ee0f87ecd 100644 --- a/src/test/java/hudson/tasks/junit/JUnitResultArchiverTest.java +++ b/src/test/java/hudson/tasks/junit/JUnitResultArchiverTest.java @@ -353,6 +353,7 @@ public void testDescribableRoundTrip() throws Exception { JUnitResultArchiver j = model.instantiate(args); assertEquals("**/TEST-*.xml", j.getTestResults()); assertFalse(j.isAllowEmptyResults()); + assertTrue(j.isMakeUnstable()); assertFalse(j.isKeepLongStdio()); assertEquals(1.0, j.getHealthScaleFactor(), 0); assertTrue(j.getTestDataPublishers().isEmpty()); From 55d9088842632e7112fd741b91b372b51c0f44b0 Mon Sep 17 00:00:00 2001 From: Nguoi An Phu Date: Thu, 28 Dec 2017 06:56:16 +0000 Subject: [PATCH 03/14] Fix test errors --- .../tasks/junit/JUnitResultArchiver.java | 18 +++++++++++++++++- .../tasks/junit/JUnitResultArchiverTest.java | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java b/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java index beb69f23e..ac9c51e51 100644 --- a/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java +++ b/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java @@ -93,6 +93,7 @@ public class JUnitResultArchiver extends Recorder implements SimpleBuildStep, JU @DataBoundConstructor public JUnitResultArchiver(String testResults) { this.testResults = testResults; + this.makeUnstable = true; } @Deprecated @@ -120,8 +121,23 @@ public JUnitResultArchiver( setTestDataPublishers(testDataPublishers == null ? Collections.emptyList() : testDataPublishers); setHealthScaleFactor(healthScaleFactor); setAllowEmptyResults(false); - setMakeUnstable(true); } + + + @Deprecated + public JUnitResultArchiver( + String testResults, + boolean keepLongStdio, + DescribableList> testDataPublishers, + double healthScaleFactor, + boolean makeUnstable) { + this.testResults = testResults; + setKeepLongStdio(keepLongStdio); + setTestDataPublishers(testDataPublishers == null ? Collections.emptyList() : testDataPublishers); + setHealthScaleFactor(healthScaleFactor); + setAllowEmptyResults(false); + setMakeUnstable(true); + } private TestResult parse(String expandedTestResults, Run run, @Nonnull FilePath workspace, Launcher launcher, TaskListener listener) throws IOException, InterruptedException diff --git a/src/test/java/hudson/tasks/junit/JUnitResultArchiverTest.java b/src/test/java/hudson/tasks/junit/JUnitResultArchiverTest.java index ee0f87ecd..0ed6ef875 100644 --- a/src/test/java/hudson/tasks/junit/JUnitResultArchiverTest.java +++ b/src/test/java/hudson/tasks/junit/JUnitResultArchiverTest.java @@ -304,6 +304,7 @@ public String getName() { @Test public void emptyDirectoryAllowEmptyResult() throws Exception { JUnitResultArchiver a = new JUnitResultArchiver("TEST-*.xml"); a.setAllowEmptyResults(true); + a.setMakeUnstable(true); FreeStyleProject freeStyleProject = j.createFreeStyleProject(); freeStyleProject.getPublishersList().add(a); j.assertBuildStatus(Result.SUCCESS, freeStyleProject.scheduleBuild2(0).get()); @@ -312,6 +313,7 @@ public String getName() { @Test public void emptyDirectory() throws Exception { JUnitResultArchiver a = new JUnitResultArchiver("TEST-*.xml"); a.setAllowEmptyResults(false); + a.setMakeUnstable(true); FreeStyleProject freeStyleProject = j.createFreeStyleProject(); freeStyleProject.getPublishersList().add(a); j.assertBuildStatus(Result.FAILURE, freeStyleProject.scheduleBuild2(0).get()); From 2b13f41b49035f972df68782c38f93b249913b37 Mon Sep 17 00:00:00 2001 From: Nguoi An Phu Date: Thu, 28 Dec 2017 09:50:03 +0000 Subject: [PATCH 04/14] Fix pipeline tests failed --- .../java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java b/src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java index f531c8bc3..274ccc11d 100644 --- a/src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java +++ b/src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java @@ -62,6 +62,7 @@ public class JUnitResultsStepTest { public void configRoundTrip() throws Exception { SnippetizerTester st = new SnippetizerTester(rule); JUnitResultsStep step = new JUnitResultsStep("**/target/surefire-reports/TEST-*.xml"); + step.setMakeUnstable(true); st.assertRoundTrip(step, "junit '**/target/surefire-reports/TEST-*.xml'"); step.setAllowEmptyResults(true); st.assertRoundTrip(step, "junit allowEmptyResults: true, testResults: '**/target/surefire-reports/TEST-*.xml'"); From da330a7a9251367586542df5ae2f0d7ad363d796 Mon Sep 17 00:00:00 2001 From: Nguoi An Phu Date: Thu, 28 Dec 2017 10:07:56 +0000 Subject: [PATCH 05/14] Revert the plugin version in pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d50559838..29e1583cc 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ junit - 1.25-SNAPSHOT + 1.24-SNAPSHOT hpi JUnit Plugin Allows JUnit-format test results to be published. From 747cb9ad882418f140755c526e0f369ad9384065 Mon Sep 17 00:00:00 2001 From: Nguoi An Phu Date: Fri, 29 Dec 2017 04:12:57 +0000 Subject: [PATCH 06/14] Increase version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 29e1583cc..d50559838 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ junit - 1.24-SNAPSHOT + 1.25-SNAPSHOT hpi JUnit Plugin Allows JUnit-format test results to be published. From 6c223169f4447abaca594f6edbb58cfd287bc812 Mon Sep 17 00:00:00 2001 From: Nguoi An Phu Date: Fri, 29 Dec 2017 07:39:42 +0000 Subject: [PATCH 07/14] Adding makeUnstable into pipeline tests --- .../tasks/junit/pipeline/JUnitResultsStepTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java b/src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java index 274ccc11d..9ec6ee287 100644 --- a/src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java +++ b/src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java @@ -63,14 +63,14 @@ public void configRoundTrip() throws Exception { SnippetizerTester st = new SnippetizerTester(rule); JUnitResultsStep step = new JUnitResultsStep("**/target/surefire-reports/TEST-*.xml"); step.setMakeUnstable(true); - st.assertRoundTrip(step, "junit '**/target/surefire-reports/TEST-*.xml'"); + st.assertRoundTrip(step, "junit makeUnstable: true, testResults: '**/target/surefire-reports/TEST-*.xml'"); step.setAllowEmptyResults(true); - st.assertRoundTrip(step, "junit allowEmptyResults: true, testResults: '**/target/surefire-reports/TEST-*.xml'"); + st.assertRoundTrip(step, "junit makeUnstable: true, allowEmptyResults: true, testResults: '**/target/surefire-reports/TEST-*.xml'"); step.setHealthScaleFactor(2.0); - st.assertRoundTrip(step, "junit allowEmptyResults: true, healthScaleFactor: 2.0, testResults: '**/target/surefire-reports/TEST-*.xml'"); + st.assertRoundTrip(step, "junit makeUnstable: true, allowEmptyResults: true, healthScaleFactor: 2.0, testResults: '**/target/surefire-reports/TEST-*.xml'"); MockTestDataPublisher publisher = new MockTestDataPublisher("testing"); step.setTestDataPublishers(Collections.singletonList(publisher)); - st.assertRoundTrip(step, "junit allowEmptyResults: true, healthScaleFactor: 2.0, testDataPublishers: [[$class: 'MockTestDataPublisher', name: 'testing']], testResults: '**/target/surefire-reports/TEST-*.xml'"); + st.assertRoundTrip(step, "junit makeUnstable: true, allowEmptyResults: true, healthScaleFactor: 2.0, testDataPublishers: [[$class: 'MockTestDataPublisher', name: 'testing']], testResults: '**/target/surefire-reports/TEST-*.xml'"); } @Issue("JENKINS-48250") @@ -111,7 +111,7 @@ public void allowEmpty() throws Exception { j.setDefinition(new CpsFlowDefinition("stage('first') {\n" + " node {\n" + " sh 'echo hi'\n" + - " def results = junit(testResults: '*.xml', allowEmptyResults: true)\n" + + " def results = junit(testResults: '*.xml', allowEmptyResults: true, makeUnstable: true)\n" + " assert results.totalCount == 0\n" + " }\n" + "}\n", true)); From 465120befb39092fe10a34dc8c2e0250d488c07c Mon Sep 17 00:00:00 2001 From: Nguoi An Phu Date: Fri, 29 Dec 2017 08:16:45 +0000 Subject: [PATCH 08/14] Fix pipeline tests errors by enabling the option makeUnstable by default --- .../tasks/junit/TestResultPublishingTest.java | 2 +- .../junit/pipeline/JUnitResultsStepTest.java | 32 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/test/java/hudson/tasks/junit/TestResultPublishingTest.java b/src/test/java/hudson/tasks/junit/TestResultPublishingTest.java index 23ce3143c..8504f53f8 100644 --- a/src/test/java/hudson/tasks/junit/TestResultPublishingTest.java +++ b/src/test/java/hudson/tasks/junit/TestResultPublishingTest.java @@ -279,7 +279,7 @@ public void testHistoryPageOpenJunit() throws IOException, SAXException { public void testBrokenResultFile() throws Exception { FreeStyleProject p = rule.createFreeStyleProject(); p.getBuildersList().add(new TestBuilder()); - p.getPublishersList().add(new JUnitResultArchiver("TEST-foo.xml", false, null)); + p.getPublishersList().add(new JUnitResultArchiver("TEST-foo.xml", true, false, null)); rule.assertBuildStatus(Result.UNSTABLE, p.scheduleBuild2(0).get()); } private static final class TestBuilder extends Builder { diff --git a/src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java b/src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java index 9ec6ee287..f030351d0 100644 --- a/src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java +++ b/src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java @@ -111,7 +111,7 @@ public void allowEmpty() throws Exception { j.setDefinition(new CpsFlowDefinition("stage('first') {\n" + " node {\n" + " sh 'echo hi'\n" + - " def results = junit(testResults: '*.xml', allowEmptyResults: true, makeUnstable: true)\n" + + " def results = junit(testResults: '*.xml', makeUnstable: true, allowEmptyResults: true)\n" + " assert results.totalCount == 0\n" + " }\n" + "}\n", true)); @@ -126,7 +126,7 @@ public void singleStep() throws Exception { WorkflowJob j = rule.jenkins.createProject(WorkflowJob.class, "singleStep"); j.setDefinition(new CpsFlowDefinition("stage('first') {\n" + " node {\n" + - " def results = junit(testResults: '*.xml')\n" + // node id 7 + " def results = junit(testResults: '*.xml', makeUnstable: true)\n" + // node id 7 " assert results.totalCount == 6\n" + " }\n" + "}\n", true)); @@ -153,8 +153,8 @@ public void twoSteps() throws Exception { WorkflowJob j = rule.jenkins.createProject(WorkflowJob.class, "twoSteps"); j.setDefinition(new CpsFlowDefinition("stage('first') {\n" + " node {\n" + - " def first = junit(testResults: 'first-result.xml')\n" + // node id 7 - " def second = junit(testResults: 'second-result.xml')\n" + // node id 8 + " def first = junit(testResults: 'first-result.xml', makeUnstable: true)\n" + // node id 7 + " def second = junit(testResults: 'second-result.xml', makeUnstable: true)\n" + // node id 8 " assert first.totalCount == 6\n" + " assert second.totalCount == 1\n" + " }\n" + @@ -191,9 +191,9 @@ public void threeSteps() throws Exception { WorkflowJob j = rule.jenkins.createProject(WorkflowJob.class, "threeSteps"); j.setDefinition(new CpsFlowDefinition("stage('first') {\n" + " node {\n" + - " def first = junit(testResults: 'first-result.xml')\n" + // node id 7 - " def second = junit(testResults: 'second-result.xml')\n" + // node id 8 - " def third = junit(testResults: 'third-result.xml')\n" + // node id 9 + " def first = junit(testResults: 'first-result.xml', makeUnstable: true)\n" + // node id 7 + " def second = junit(testResults: 'second-result.xml', makeUnstable: true)\n" + // node id 8 + " def third = junit(testResults: 'third-result.xml', makeUnstable: true)\n" + // node id 9 " assert first.totalCount == 6\n" + " assert second.totalCount == 1\n" + " }\n" + @@ -247,9 +247,9 @@ public void parallelInStage() throws Exception { j.setDefinition(new CpsFlowDefinition("stage('first') {\n" + " node {\n" + - " parallel(a: { def first = junit(testResults: 'first-result.xml'); assert first.totalCount == 6 },\n" + - " b: { def second = junit(testResults: 'second-result.xml'); assert second.totalCount == 1 },\n" + - " c: { def third = junit(testResults: 'third-result.xml'); assert third.totalCount == 3 })\n" + + " parallel(a: { def first = junit(testResults: 'first-result.xml', makeUnstable: true); assert first.totalCount == 6 },\n" + + " b: { def second = junit(testResults: 'second-result.xml', makeUnstable: true); assert second.totalCount == 1 },\n" + + " c: { def third = junit(testResults: 'third-result.xml', makeUnstable: true); assert third.totalCount == 3 })\n" + " }\n" + "}\n", true )); @@ -280,9 +280,9 @@ public void stageInParallel() throws Exception { j.setDefinition(new CpsFlowDefinition("stage('outer') {\n" + " node {\n" + - " parallel(a: { stage('a') { def first = junit(testResults: 'first-result.xml'); assert first.totalCount == 6 } },\n" + - " b: { stage('b') { def second = junit(testResults: 'second-result.xml'); assert second.totalCount == 1 } },\n" + - " c: { stage('d') { def third = junit(testResults: 'third-result.xml'); assert third.totalCount == 3 } })\n" + + " parallel(a: { stage('a') { def first = junit(testResults: 'first-result.xml', makeUnstable: true); assert first.totalCount == 6 } },\n" + + " b: { stage('b') { def second = junit(testResults: 'second-result.xml', makeUnstable: true); assert second.totalCount == 1 } },\n" + + " c: { stage('d') { def third = junit(testResults: 'third-result.xml', makeUnstable: true); assert third.totalCount == 3 } })\n" + " }\n" + "}\n", true )); @@ -308,10 +308,10 @@ public void testTrends() throws Exception { WorkflowJob j = rule.jenkins.createProject(WorkflowJob.class, "testTrends"); j.setDefinition(new CpsFlowDefinition("node {\n" + " stage('first') {\n" + - " def first = junit(testResults: \"junit-report-testTrends-first.xml\")\n" + + " def first = junit(testResults: \"junit-report-testTrends-first.xml\", makeUnstable: true)\n" + " }\n" + " stage('second') {\n" + - " def second = junit(testResults: \"junit-report-testTrends-second.xml\")\n" + + " def second = junit(testResults: \"junit-report-testTrends-second.xml\", makeUnstable: true)\n" + " }\n" + "}\n", true)); FilePath ws = rule.jenkins.getWorkspaceFor(j); @@ -371,7 +371,7 @@ public void currentBuildResultUnstable() throws Exception { WorkflowJob j = rule.jenkins.createProject(WorkflowJob.class, "currentBuildResultUnstable"); j.setDefinition(new CpsFlowDefinition("stage('first') {\n" + " node {\n" + - " def results = junit(testResults: '*.xml')\n" + // node id 7 + " def results = junit(testResults: '*.xml', makeUnstable: true)\n" + // node id 7 " assert results.totalCount == 8\n" + " assert currentBuild.result == 'UNSTABLE'\n" + " }\n" + From e073e0ed20a0abb03da993d53c60b88a803d5dc2 Mon Sep 17 00:00:00 2001 From: Nguoi An Phu Date: Fri, 29 Dec 2017 09:31:13 +0000 Subject: [PATCH 09/14] Fix complation errors --- src/main/java/hudson/tasks/junit/JUnitResultArchiver.java | 1 + src/test/java/hudson/tasks/junit/TestResultPublishingTest.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java b/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java index ac9c51e51..4a15a053c 100644 --- a/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java +++ b/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java @@ -108,6 +108,7 @@ public JUnitResultArchiver( boolean keepLongStdio, DescribableList> testDataPublishers) { this(testResults, keepLongStdio, testDataPublishers, 1.0); + this.makeUnstable = true; } @Deprecated diff --git a/src/test/java/hudson/tasks/junit/TestResultPublishingTest.java b/src/test/java/hudson/tasks/junit/TestResultPublishingTest.java index 8504f53f8..23ce3143c 100644 --- a/src/test/java/hudson/tasks/junit/TestResultPublishingTest.java +++ b/src/test/java/hudson/tasks/junit/TestResultPublishingTest.java @@ -279,7 +279,7 @@ public void testHistoryPageOpenJunit() throws IOException, SAXException { public void testBrokenResultFile() throws Exception { FreeStyleProject p = rule.createFreeStyleProject(); p.getBuildersList().add(new TestBuilder()); - p.getPublishersList().add(new JUnitResultArchiver("TEST-foo.xml", true, false, null)); + p.getPublishersList().add(new JUnitResultArchiver("TEST-foo.xml", false, null)); rule.assertBuildStatus(Result.UNSTABLE, p.scheduleBuild2(0).get()); } private static final class TestBuilder extends Builder { From cbabf38f06ddaddf4d63f71f6729902c0fcb679b Mon Sep 17 00:00:00 2001 From: Nguoi An Phu Date: Fri, 29 Dec 2017 10:04:45 +0000 Subject: [PATCH 10/14] Fix failed test in JUnitResultsStepTest --- .../hudson/tasks/junit/pipeline/JUnitResultsStepTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java b/src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java index f030351d0..196cf42d6 100644 --- a/src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java +++ b/src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java @@ -65,12 +65,12 @@ public void configRoundTrip() throws Exception { step.setMakeUnstable(true); st.assertRoundTrip(step, "junit makeUnstable: true, testResults: '**/target/surefire-reports/TEST-*.xml'"); step.setAllowEmptyResults(true); - st.assertRoundTrip(step, "junit makeUnstable: true, allowEmptyResults: true, testResults: '**/target/surefire-reports/TEST-*.xml'"); + st.assertRoundTrip(step, "junit allowEmptyResults: true, makeUnstable: true, testResults: '**/target/surefire-reports/TEST-*.xml'"); step.setHealthScaleFactor(2.0); - st.assertRoundTrip(step, "junit makeUnstable: true, allowEmptyResults: true, healthScaleFactor: 2.0, testResults: '**/target/surefire-reports/TEST-*.xml'"); + st.assertRoundTrip(step, "junit allowEmptyResults: true, makeUnstable: true, healthScaleFactor: 2.0, testResults: '**/target/surefire-reports/TEST-*.xml'"); MockTestDataPublisher publisher = new MockTestDataPublisher("testing"); step.setTestDataPublishers(Collections.singletonList(publisher)); - st.assertRoundTrip(step, "junit makeUnstable: true, allowEmptyResults: true, healthScaleFactor: 2.0, testDataPublishers: [[$class: 'MockTestDataPublisher', name: 'testing']], testResults: '**/target/surefire-reports/TEST-*.xml'"); + st.assertRoundTrip(step, "junit allowEmptyResults: true, makeUnstable: true, healthScaleFactor: 2.0, testDataPublishers: [[$class: 'MockTestDataPublisher', name: 'testing']], testResults: '**/target/surefire-reports/TEST-*.xml'"); } @Issue("JENKINS-48250") From ff6106219bbfd31494580120514289ccbba50620 Mon Sep 17 00:00:00 2001 From: Nguoi An Phu Date: Fri, 29 Dec 2017 10:16:42 +0000 Subject: [PATCH 11/14] Fix failed test in JUnitResultsStepTest.configRoundTrip --- .../hudson/tasks/junit/pipeline/JUnitResultsStepTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java b/src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java index 196cf42d6..aa429fae5 100644 --- a/src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java +++ b/src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java @@ -67,10 +67,10 @@ public void configRoundTrip() throws Exception { step.setAllowEmptyResults(true); st.assertRoundTrip(step, "junit allowEmptyResults: true, makeUnstable: true, testResults: '**/target/surefire-reports/TEST-*.xml'"); step.setHealthScaleFactor(2.0); - st.assertRoundTrip(step, "junit allowEmptyResults: true, makeUnstable: true, healthScaleFactor: 2.0, testResults: '**/target/surefire-reports/TEST-*.xml'"); + st.assertRoundTrip(step, "junit allowEmptyResults: true, healthScaleFactor: 2.0, makeUnstable: true, testResults: '**/target/surefire-reports/TEST-*.xml'"); MockTestDataPublisher publisher = new MockTestDataPublisher("testing"); step.setTestDataPublishers(Collections.singletonList(publisher)); - st.assertRoundTrip(step, "junit allowEmptyResults: true, makeUnstable: true, healthScaleFactor: 2.0, testDataPublishers: [[$class: 'MockTestDataPublisher', name: 'testing']], testResults: '**/target/surefire-reports/TEST-*.xml'"); + st.assertRoundTrip(step, "junit allowEmptyResults: true, healthScaleFactor: 2.0, makeUnstable: true, testDataPublishers: [[$class: 'MockTestDataPublisher', name: 'testing']], testResults: '**/target/surefire-reports/TEST-*.xml'"); } @Issue("JENKINS-48250") From 81a1a2cc7009284da082739e9b4dde16b6b84036 Mon Sep 17 00:00:00 2001 From: Nguoi An Phu Date: Fri, 29 Dec 2017 10:24:47 +0000 Subject: [PATCH 12/14] Fix failed test in JUnitResultsStepTest due to spaces --- .../hudson/tasks/junit/pipeline/JUnitResultsStepTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java b/src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java index aa429fae5..1ab9315e6 100644 --- a/src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java +++ b/src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java @@ -67,10 +67,10 @@ public void configRoundTrip() throws Exception { step.setAllowEmptyResults(true); st.assertRoundTrip(step, "junit allowEmptyResults: true, makeUnstable: true, testResults: '**/target/surefire-reports/TEST-*.xml'"); step.setHealthScaleFactor(2.0); - st.assertRoundTrip(step, "junit allowEmptyResults: true, healthScaleFactor: 2.0, makeUnstable: true, testResults: '**/target/surefire-reports/TEST-*.xml'"); + st.assertRoundTrip(step, "junit allowEmptyResults: true, healthScaleFactor: 2.0, makeUnstable: true, testResults: '**/target/surefire-reports/TEST-*.xml'"); MockTestDataPublisher publisher = new MockTestDataPublisher("testing"); step.setTestDataPublishers(Collections.singletonList(publisher)); - st.assertRoundTrip(step, "junit allowEmptyResults: true, healthScaleFactor: 2.0, makeUnstable: true, testDataPublishers: [[$class: 'MockTestDataPublisher', name: 'testing']], testResults: '**/target/surefire-reports/TEST-*.xml'"); + st.assertRoundTrip(step, "junit allowEmptyResults: true, healthScaleFactor: 2.0, makeUnstable: true, testDataPublishers: [[$class: 'MockTestDataPublisher', name: 'testing']], testResults: '**/target/surefire-reports/TEST-*.xml'"); } @Issue("JENKINS-48250") From 59f7b8a3e5ddbf8031bc90749ad13f6b7464fa47 Mon Sep 17 00:00:00 2001 From: Nguoi An Phu Date: Wed, 1 Apr 2020 15:51:28 +0700 Subject: [PATCH 13/14] Fix @aabrahamian by adding braces --- src/main/java/hudson/tasks/junit/JUnitResultArchiver.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java b/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java index 8471194f7..963d0b956 100644 --- a/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java +++ b/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java @@ -172,7 +172,7 @@ public void perform(Run build, FilePath workspace, Launcher launcher, TaskListener listener) throws InterruptedException, IOException { TestResultAction action = parseAndAttach(this, null, build, workspace, launcher, listener); - if (action != null && action.getResult().getFailCount() > 0) + if ((action != null) && (action.getResult().getFailCount() > 0)) build.setResult(Result.UNSTABLE); listener.getLogger().println(Messages.JUnitResultArchiver_ChangeState("UNSTABLE")); } From 7cb0960aa45c11dc6a091d1ea9f3380c0aa89e68 Mon Sep 17 00:00:00 2001 From: Emanuele Levorin Date: Thu, 22 Oct 2020 22:30:02 +0200 Subject: [PATCH 14/14] add help-makeUnstable --- .../tasks/junit/JUnitResultArchiver/help-makeUnstable.html | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/resources/hudson/tasks/junit/JUnitResultArchiver/help-makeUnstable.html diff --git a/src/main/resources/hudson/tasks/junit/JUnitResultArchiver/help-makeUnstable.html b/src/main/resources/hudson/tasks/junit/JUnitResultArchiver/help-makeUnstable.html new file mode 100644 index 000000000..77393d8da --- /dev/null +++ b/src/main/resources/hudson/tasks/junit/JUnitResultArchiver/help-makeUnstable.html @@ -0,0 +1,7 @@ +
+ If set to false, the default behavior of making the build unstable + for failed test result files is changed to not affect the status of the build. + Please note that this setting make it impossible to spot misconfigured jobs or + build failures where the test tool does not exit with an error code when + producing or not test report files. +
\ No newline at end of file