Skip to content

Commit

Permalink
[FIXED JENKINS-48178] Set run result rather than context result
Browse files Browse the repository at this point in the history
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 acd8f48
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Expand Up @@ -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));
}
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

1 comment on commit acd8f48

@IKOBH
Copy link

@IKOBH IKOBH commented on acd8f48 Mar 7, 2018

Choose a reason for hiding this comment

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

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

Please sign in to comment.