Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-73421] Expose getExternalizableId() in RunWrapper API #268

Merged
merged 8 commits into from
Jul 10, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ public String getId() throws AbortException {
return build().getId();
}

@Whitelisted
public String getExternalizableId() {
return externalizableId;
}

/**
* Get environment variables defined in the build.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<dt><code>fullProjectName</code></dt><dd>Full name of the project of this build, including folders such as <code>folder1/folder2/foo</code>.</dd>
<dt><code>description</code></dt><dd>additional information about the build</dd>
<dt><code>id</code></dt><dd>normally <code>number</code> as a string</dd>
<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>
<dt><code>timeInMillis</code></dt><dd>time since the epoch when the build was scheduled</dd>
<dt><code>startTimeInMillis</code></dt><dd>time since the epoch when the build started running</dd>
<dt><code>duration</code></dt><dd>duration of the build in milliseconds</dd>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,17 @@ public void upstreamBuilds() throws Throwable {
});
}

@Test
@Issue("JENKINS-73421")
public void externalizableId() throws Throwable {
sessions.then(j -> {
WorkflowJob first = j.createProject(WorkflowJob.class, "first-job");
first.setDefinition(new CpsFlowDefinition("echo(/externalizableId=$currentBuild.externalizableId/)", true));
WorkflowRun firstRun = j.buildAndAssertSuccess(first);
j.assertLogContains("externalizableId=" + firstRun.getExternalizableId(), firstRun);
});
}

// 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("containing the regexp", false, rx) {
Expand Down
Loading