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
243
}
244
+
if (allowBRANCH_NAME) {
245
+
returnFormValidation.error("If you allow use of literal '@${BRANCH_NAME}' for overriding a default version, you must define that version as fallback.");
246
+
}
180
247
if (!allowVersionOverride) {
181
248
returnFormValidation.error("If you deny overriding a default version, you must define that version.");
182
249
}
183
250
returnFormValidation.ok();
184
251
} else {
252
+
if ("${BRANCH_NAME}".equals(defaultVersion)) {
253
+
if (!allowBRANCH_NAME) {
254
+
returnFormValidation.error("Use of literal '@${BRANCH_NAME}' not allowed in this configuration.");
255
+
}
256
+
257
+
// The context is not a particular Run (might be a Job)
258
+
// so we can't detect which BRANCH_NAME is relevant:
259
+
Stringmsg = "Cannot validate default version: " +
260
+
"literal '@${BRANCH_NAME}' is reserved " +
261
+
"for pipeline files from SCM";
262
+
if (implicit) {
263
+
// Someone might want to bind feature branches of
264
+
// job definitions and implicit libs by default?..
265
+
returnFormValidation.warning(msg);
266
+
} else {
267
+
returnFormValidation.error(msg);
268
+
}
269
+
}
270
+
185
271
for (LibraryResolverresolver : ExtensionList.lookup(LibraryResolver.class)) {
186
272
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