Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working with versions on Jenkins Pipeline Shared Libraries

I'm trying to figure it out on how to work with a specific version of a Shared Library.

Jenkins documentation about this isn't quite clear so I've being making some experimenting but with no success.

They basically say:

enter image description here

But how should I configure somelib on 'Global Pipeline Libraries' section under Manage Jenkins > System Config menu so I can use any of the available stable versions?!

The thing is: Imagine that I've my somelib Project under version control and, currently, I've released 2 stable versions of it: v0.1 and v0.2 (so I have 2 tags named v0.1 and v0.2).

And in some Pipeline I want to use somelib's version v0.1 and on another Pipeline I need to use v0.2 version.

How can I do this using the @Library annotation provided by Jenkins?

like image 867
Cristian Gonçalves Avatar asked Jan 19 '17 12:01

Cristian Gonçalves


People also ask

Where do you configure a shared global library in Jenkins?

Set up the library in Jenkins To add your shared library (I'm using my demo repository on GitHub as an example): In Jenkins, go to Manage Jenkins → Configure System. Under Global Pipeline Libraries, add a library with the following settings: Name: pipeline-library-demo.

Where does Jenkins checkout shared library?

If the shared library is loaded from SCM and your workspace path is jenkins/workspaces/jobName , then a copy is checked out to jenkins/workspaces/jobName@libs or similar (might be suffixed with a number if that path is occupied by another concurrent build).

What are the 3 types of pipelines in Jenkins?

Different Types of Jenkins CI/CD Pipelines. Scripted Pipeline. Declarative Pipeline.


1 Answers

In the Global Pipeline Libraries under Jenkins > System Config you only set the default library version to use if not specified otherwise inside the Jenkinsfile. This might look like this (ignore the Failed to connect to repo error here):

enter image description here

Inside the Jenkinsfile you can explicitly specify which version you want to use if you do not want the default:

@Library('somelib@<tag/branch/commitRef>')

That way you can freely choose at any time which pipeline version to use for you project.

like image 62
fishi0x01 Avatar answered Nov 15 '22 06:11

fishi0x01