Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-42521] Add RunWrapper.getCurrentResult()
getCurrentResult() will never be null - if build().getResult() is
null, it'll return Result.SUCCESS.toString(). In a perfect world, I'd
change RunWrapper.getResult() to this behavior, but that'd possibly
break existing logic out in the wild, so a new method it is.
  • Loading branch information
abayer committed Mar 6, 2017
1 parent 6fce277 commit 26b0898
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Expand Up @@ -121,6 +121,12 @@ public int getNumber() throws AbortException {
return result != null ? result.toString() : null;
}

@Whitelisted
public @Nonnull String getCurrentResult() throws AbortException {
Result result = build().getResult();
return result != null ? result.toString() : Result.SUCCESS.toString();
}

@Whitelisted
public long getTimeInMillis() throws AbortException {
return build().getTimeInMillis();
Expand Down
Expand Up @@ -166,6 +166,24 @@ public class RunWrapperTest {
});
}

@Issue("JENKINS-37366")
@Test public void getCurrentResult() {
r.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
MockFolder folder = r.j.createFolder("this-folder");
WorkflowJob p = folder.createProject(WorkflowJob.class, "current-result-job");
p.setDefinition(new CpsFlowDefinition(
"echo \"initial currentBuild.currentResult='${currentBuild.currentResult}'\"\n" +
"currentBuild.result = 'UNSTABLE'\n" +
"echo \"final currentBuild.currentResult='${currentBuild.currentResult}'\"\n",
true));
WorkflowRun b = r.j.assertBuildStatus(Result.UNSTABLE, p.scheduleBuild2(0).get());
r.j.assertLogContains("initial currentBuild.currentResult='" + Result.SUCCESS.toString() + "'", b);
r.j.assertLogContains("final currentBuild.currentResult='" + Result.UNSTABLE.toString() + "'", b);
}
});
}

// Like org.hamcrest.text.MatchesPattern.matchesPattern(String) but doing a substring, not whole-string, match:
private static Matcher<String> containsRegexp(final String rx) {
return new SubstringMatcher(rx) {
Expand Down

0 comments on commit 26b0898

Please sign in to comment.