Working with versions on Jenkins Pipeline Shared Libraries
Asked Answered
L

3

6

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?

Lardy answered 19/1, 2017 at 12:51 Comment(0)
C
8

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.

Cyano answered 19/1, 2017 at 13:9 Comment(1)
Oh right! Things now make sense. Thanks a lot for your kindly help @fishiFeathers
L
2

Following @fishi response I just want to leave an important note.

During library configuration on Global Pipeline Libraries you must select Modern SCM option so things can work seamlessly.

If you select Legacy Mode instead you'll not be able to use the library as desired.

If for some reason Modern SCM does not appear in the Retrieval Mode option it means that you need to upgrade Global Pipeline Libraries plugin or even Jenkins

Lardy answered 27/1, 2017 at 10:25 Comment(1)
Loading libraries with Legacy SCM is working as expected for me. At least for folder-level shared libraries.Confession
J
0

Basically "Version" is the branch name for the repo which stores the shared library codes. If you don't have any branch other than main or master, make sure to fill it in Default Version in your Global Pipeline Library configuration

Jasun answered 1/11, 2022 at 10:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.