Skip to content

Commit c71c40c

Browse files
authored
Merge pull request jenkinsci#268 from stuartrowe/JENKINS-73421
[JENKINS-73421] Expose getExternalizableId() in RunWrapper API
2 parents 6713aed + b76885c commit c71c40c

File tree

3 files changed

+17
-0
lines changed
  • src
    • main
      • java/org/jenkinsci/plugins/workflow/support/steps/build
      • resources/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapper
    • test/java/org/jenkinsci/plugins/workflow/support/steps/build

3 files changed

+17
-0
lines changed

src/main/java/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,11 @@ public String getId() throws AbortException {
314314
return build().getId();
315315
}
316316

317+
@Whitelisted
318+
public String getExternalizableId() {
319+
return externalizableId;
320+
}
321+
317322
/**
318323
* Get environment variables defined in the build.
319324
*

src/main/resources/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapper/help.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<dt><code>fullProjectName</code></dt><dd>Full name of the project of this build, including folders such as <code>folder1/folder2/foo</code>.</dd>
1313
<dt><code>description</code></dt><dd>additional information about the build</dd>
1414
<dt><code>id</code></dt><dd>normally <code>number</code> as a string</dd>
15+
<dt><code>externalizableId</code></dt><dd>identifier for this build from combining <code>fullProjectName</code> and <code>number</code> as <code>fullProjectName#number</code></dd>
1516
<dt><code>timeInMillis</code></dt><dd>time since the epoch when the build was scheduled</dd>
1617
<dt><code>startTimeInMillis</code></dt><dd>time since the epoch when the build started running</dd>
1718
<dt><code>duration</code></dt><dd>duration of the build in milliseconds</dd>

src/test/java/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapperTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,17 @@ public void upstreamBuilds() throws Throwable {
287287
});
288288
}
289289

290+
@Test
291+
@Issue("JENKINS-73421")
292+
public void externalizableId() throws Throwable {
293+
sessions.then(j -> {
294+
WorkflowJob first = j.createProject(WorkflowJob.class, "first-job");
295+
first.setDefinition(new CpsFlowDefinition("echo(/externalizableId=$currentBuild.externalizableId/)", true));
296+
WorkflowRun firstRun = j.buildAndAssertSuccess(first);
297+
j.assertLogContains("externalizableId=" + firstRun.getExternalizableId(), firstRun);
298+
});
299+
}
300+
290301
// Like org.hamcrest.text.MatchesPattern.matchesPattern(String) but doing a substring, not whole-string, match:
291302
private static Matcher<String> containsRegexp(final String rx) {
292303
return new SubstringMatcher("containing the regexp", false, rx) {

0 commit comments

Comments
 (0)