Skip to content
Permalink
Browse files

[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 26b089847fb20d164f45424f757cef6da7ffc56c
@@ -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();
@@ -166,6 +166,24 @@
});
}

@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) {

0 comments on commit 26b0898

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