Skip to content
Permalink
Browse files

[FIXED JENKINS-48178] Set run result rather than context result

This fixes currentBuild.result to be UNSTABLE after test failures are
encountered. We'll want to revisit this in the future once we have
more granular stage/step status, but going with
getContext().setResult(...) was, in retrospect, premature optimization.
  • Loading branch information...
abayer committed Nov 23, 2017
1 parent f207e31 commit acd8f4843602a4629344f4cb404cec2dfb7a54d2
@@ -50,8 +50,8 @@ protected TestResultSummary run() throws Exception {

if (testResultAction != null) {
// TODO: Once JENKINS-43995 lands, update this to set the step status instead of the entire build.
if (testResultAction.getResult().getFailCount() > 0) {
getContext().setResult(Result.UNSTABLE);
if (testResultAction.getResult().getFailCount() > 0 && run != null) {
run.setResult(Result.UNSTABLE);
}
return new TestResultSummary(testResultAction.getResult().getResultByNode(nodeId));
}
@@ -28,6 +28,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.TestExtension;
import org.kohsuke.stapler.DataBoundConstructor;
@@ -303,6 +304,25 @@ public void testTrends() throws Exception {
}
}

@Issue("JENKINS-48178")
@Test
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
" assert results.totalCount == 8\n" +
" assert currentBuild.result == 'SUCCESS'\n" +
" }\n" +
"}\n", true));
FilePath ws = rule.jenkins.getWorkspaceFor(j);
FilePath testFile = ws.child("test-result.xml");
testFile.copyFrom(JUnitResultsStepTest.class.getResource("junit-report-testTrends-first-2.xml"));

rule.assertBuildStatus(Result.UNSTABLE, rule.waitForCompletion(j.scheduleBuild2(0).waitForStart()));
}


private static Predicate<FlowNode> branchForName(final String name) {
return new Predicate<FlowNode>() {
@Override

1 comment on commit acd8f48

@IKOBH

This comment has been minimized.

Copy link

commented on acd8f48 Mar 7, 2018

Hi.
How do I use this patch with my jenkinsci/blueocean docker image?
Thanks

Please sign in to comment.
You can’t perform that action at this time.