Reputation: 639
I have a repository for a jenkins shared library named "jenkins-shared-library" , now I created a new branch called "test",
I have an application that need to use this jenkins shared library inside a jenkins file, currently it is being referred as
@Library('jenkins-shared-library')_
I want to use this specific test branch of my jenkins-shared-library inside my jenkinsfile, how can I use the specific branch of jenkins-shared-library???
Upvotes: 17
Views: 24017
Reputation: 39
Also can be done in Manage Jenkins > Configure System
under: Global Pipeline Libraries change the Default version
Upvotes: 1
Reputation: 314
You can use the 'test' branch simply by declaring it as
@Library('jenkins-shared-library@test')_
Upvotes: 7
Reputation: 6859
Take a look at the Shared Libraries Documentation, there are several ways to control the version of a shared library across the pipelines.
First option is to define the version in Global Pipeline Libraries configuration - which will affect all the pipelines that are using that library.
The second option, which is probably what you need is to use the version specifier when loading the library, the format will be @Library('my-shared-library@<BranchName>')
. The version specifier can be a branch name, a git tag and so.
// Using a version specifier, such as branch, tag, etc
@Library('[email protected]') _
// Accessing multiple libraries with one statement
@Library(['my-shared-library', 'otherlib@abc1234']) _
Important If you want to override the version of a default library defined in the in Global Pipeline Libraries you must enable the Allow default version to be overridden in the Shared Library’s configuration - or else you wont be able to use a custom version.
When loading libraries dynamically (using the library
step) you can also specify a version: library 'my-shared-library@master'
, and since this is a regular step, the version could be computed at runtime rather than just using a constant value as with the annotation.
for example: library "my-shared-library@$BRANCH_NAME"
Upvotes: 21