You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
LibraryConfiguration: extend with allowBRANCH_NAME for literal use of @Library('libname@${BRANCH_NAME}') [JENKINS-69731]
To simplify co-existence of feature-branched pipeline scripts with
feature-branched Jenkins Shared Libraries, allow literal use of
@Library('libname@${BRANCH_NAME}') _
lines to load a variant of a trusted (global) library with one case
of arbitrary branch naming.
This should be permitted by allowBRANCH_NAME checkbox (independent
of generic allowVersionOverride setting) in the first place.
If enabled, the value of BRANCH_NAME environment variable set by
the current build's Run object would be queried, and if resolvable -
verified with retriever.validateVersion() to match the backend
(Legacy SCM, Modern SCM, and other retrievers like HTTP/ZIP from
workflow-cps-global-lib-http-plugin).
returnFormValidation.error("If you load a library implicitly, you must specify a default version.");
179
244
}
245
+
if (allowBRANCH_NAME) {
246
+
returnFormValidation.error("If you allow use of literal '@${BRANCH_NAME}' for overriding a default version, you must define that version as fallback.");
247
+
}
180
248
if (!allowVersionOverride) {
181
249
returnFormValidation.error("If you deny overriding a default version, you must define that version.");
182
250
}
183
251
returnFormValidation.ok();
184
252
} else {
253
+
if ("${BRANCH_NAME}".equals(defaultVersion)) {
254
+
if (!allowBRANCH_NAME) {
255
+
returnFormValidation.error("Use of literal '@${BRANCH_NAME}' not allowed in this configuration.");
256
+
}
257
+
258
+
// The context is not a particular Run (might be a Job)
259
+
// so we can't detect which BRANCH_NAME is relevant:
260
+
Stringmsg = "Cannot validate default version: " +
261
+
"literal '@${BRANCH_NAME}' is reserved " +
262
+
"for pipeline files from SCM";
263
+
if (implicit) {
264
+
// Someone might want to bind feature branches of
265
+
// job definitions and implicit libs by default?..
266
+
returnFormValidation.warning(msg);
267
+
} else {
268
+
returnFormValidation.error(msg);
269
+
}
270
+
}
271
+
185
272
for (LibraryResolverresolver : ExtensionList.lookup(LibraryResolver.class)) {
186
273
for (LibraryConfigurationconfig : resolver.fromConfiguration(Stapler.getCurrentRequest())) {
Copy file name to clipboardExpand all lines: src/main/resources/org/jenkinsci/plugins/workflow/libs/LibraryConfiguration/config.jelly
+3Lines changed: 3 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -37,6 +37,9 @@ THE SOFTWARE.
37
37
<f:entryfield="allowVersionOverride"title="${%Allow default version to be overridden}">
38
38
<f:checkboxdefault="true"/>
39
39
</f:entry>
40
+
<f:entryfield="allowBRANCH_NAME"title="${%Allow literal use of @Library 'libname@$${BRANCH_NAME}' in pipeline scripts from SCM; falls back to default version if BRANCH_NAME is not available or not found}">
41
+
<f:checkboxdefault="false"/>
42
+
</f:entry>
40
43
<f:entryfield="includeInChangesets"title="${%Include @Library changes in job recent changes}">
0 commit comments