-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Hacktoberfest [JENKINS-69731] Update shared-libraries.adoc #5537
Draft
jimklimov
wants to merge
5
commits into
jenkins-infra:master
Choose a base branch
from
jimklimov:patch-12
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+58
−0
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
df0dc5a
Update shared-libraries.adoc
jimklimov 15a3334
Update shared-libraries.adoc
jimklimov fd44057
Update content/doc/book/pipeline/shared-libraries.adoc
jimklimov 0c3b6a1
Update content/doc/book/pipeline/shared-libraries.adoc
jimklimov 0321b94
Update shared-libraries.adoc
jimklimov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -194,6 +194,64 @@ A link to the example repository used is also provided in the link:https://youtu | |||||
|
||||||
video::eV7roTXrEqg[youtube,width=800,height=420] | ||||||
|
||||||
=== Statically loading evaluated versions of libraries | ||||||
|
||||||
As of currently unreleased version of the _Pipeline: Shared Groovy Libraries_ plugin, | ||||||
with features proposed in | ||||||
link:https://github.com/jenkinsci/pipeline-groovy-lib-plugin/pull/19[PR #19] | ||||||
(link:https://issues.jenkins.io/browse/JENKINS-69731[issue JENKINS-69731]) | ||||||
there are new options for the `@Library` annotation with limited run-time evaluation | ||||||
of the version specified for the library. In order to use these features, you should | ||||||
explicitly allow them in library configuration (e.g. Global Jenkins configuration of | ||||||
your instance). | ||||||
|
||||||
While the markup for these features is intentionally similar to what you would write | ||||||
for Groovy code to simplify maintenance, keep in mind that the version tokens are | ||||||
handled by the plugin before it would load libraries and compile the pipeline script. | ||||||
|
||||||
One addressed use-case regards loading of "same version of library as the version of | ||||||
Pipeline script from SCM" by specifying literally +`${BRANCH_NAME}`+ as the library | ||||||
version in the pipeline script, e.g.: | ||||||
|
||||||
[source,groovy] | ||||||
---- | ||||||
@Library('my-shared-library@${BRANCH_NAME}') _ | ||||||
---- | ||||||
|
||||||
The plugin tries several methods to determine the branch name to use, checks if | ||||||
the "version" is accepted by the SCM source of the library, and falls back to the default | ||||||
version if not. | ||||||
|
||||||
This was verified to work for: | ||||||
* MultiBranch Project pipelines both with "Modern SCM" and with "Single repository & branch" | ||||||
(in case of the latter, the "name" you specify for the source is what matters for MBP more | ||||||
than the actual SCM branch); | ||||||
* Pipelines backed by a single SCM source with a "Branch Specifier" like `*/main`; | ||||||
* "In-line" Pipelines not backed by an SCM (just fall back to default version). | ||||||
|
||||||
Another addressed use-case regards loading of some version of library specified by | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly simpler phrasing?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about this change (alone) since an earlier paragraph stressed that "one use-case is..." so here "another"... |
||||||
an environment variable value defined when the job starts (e.g. coming from Global | ||||||
Jenkins configuration or injected by a plugin): | ||||||
|
||||||
[source,groovy] | ||||||
---- | ||||||
@Library('my-shared-library@${env.CUSTOM_VAR_NAME}') _ | ||||||
---- | ||||||
|
||||||
The plugin would try to get the `CUSTOM_VAR_NAME` from environment, and if it exists -- | ||||||
check if such "version" is accepted by SCM source of the library, and fall back to | ||||||
default version if not. | ||||||
|
||||||
Note that pipeline sources before inclusion of `@Library` sources are parsed by the | ||||||
"built-in" build agent, so configuration of separate build agents should not matter | ||||||
in this context. This approach however allows to set up different Jenkins controllers | ||||||
to run the same pipeline scripts that would load different library sources based on | ||||||
the global-configuration value of `CUSTOM_VAR_NAME` on each Jenkins server. This can | ||||||
be useful to balance different implementations for different build farms and tooling | ||||||
(in-house proprietary for supported product vs. reference recipes for open source | ||||||
community), or different preferences to progress through dev/qa/staging/production | ||||||
separate environments. | ||||||
|
||||||
=== Loading libraries dynamically | ||||||
|
||||||
As of version 2.7 of the _Pipeline: Shared Groovy Libraries_ plugin, | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for phrasing it that way to make it clear to reviewers like me that the feature is not yet released. Very nice technique!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose you did not mean removing these lines, just yet? :)
(If this PR is indeed only merged after the feature release, this should get rephrased similar to
library
step description)