Jump to content
Sign in to follow this  
Evgeny

Jenkins Shared libraries version

Recommended Posts

Hi,

 

I'm currently trying to setup shared libraries to use different versions. 

Example use-case: Test job, that will use /main/development branch, where i can experiment with shared libraries and not ruining all production jobs.

 

1) First of all i tryed to set branch explicitly to "/main/development":

image.png.d38a04b360b2beef9e3d397c5bf02dd1.png

It works, as expected. But i can't see this selector in Jenkins log. Log looks loke this, and only in changesets i can see, that new selector actually worked

image.thumb.png.8e52fc6ca86c3d17153a1bb5023bd890.png

 

2) After that a tryed to setup lybrary versions for legacy SCM, as described in documentation (https://www.jenkins.io/doc/book/pipeline/shared-libraries/)

Here are shared libraries settings:

image.thumb.png.91849208a294434cfd284d73528d0454.png

 

Build fails with the same error. I tryed:

- Default version = "/main"

- Default version = "/main/development"

- @Library('Default@main/development') in pipeline script

 

Maybe i'm making some stupid error in setup, but i have no means to debug that, as i can't get final selector from log.

image.thumb.png.7bdf6e5e6d76bab5a1e14f0cc75d3455.png

Log shows only last succesful selector, and that new selector are saved to txt file, that instantly gets deleted.

I checked, that both selectors ("/main" and "/main/development"), written explicitly in settings - works as expected. But "${library.Default.version}" shows an error.

 

What i'm doing wrong? Or how i can see actual selector, that are generated in txt file?

Share this post


Link to post
Share on other sites
Quote

It works, as expected. But i can't see this selector in Jenkins log. Log looks loke this, and only in changesets i can see, that new selector actually worked

The Plastic plugin uses the "cm sts --help command and the selector is taken from a text file (based on the same selector you enter in your configuration panel). If I properly understand, this is properly working.

 

Quote

I checked, that both selectors ("/main" and "/main/development"), written explicitly in settings - works as expected. But "${library.Default.version}" shows an error

Could you configure your build to "echo ${library.Default.version}"? we need to be sure this value is properly resolved and the format is correct.

Anyway, if you want to use shared libraries, please check the steps from "Mikael Kalms" in the following thread:

 

You should be able to repro this by setting up an empty Plastic repo as your Global Shared Library, and another Plastic repo containing a single-line Jenkinsfile:

    @Library('JenkinsBuildScripts@latest') _

 

Regards,

Carlos.

Share this post


Link to post
Share on other sites
I tryed "echo ${library.Default.version}" and get an error
hudson.remoting.ProxyException: groovy.lang.MissingPropertyException: No such property: library for class: WorkflowScript

Share this post


Link to post
Share on other sites

Hi Evgeny,

I've running some tests and I don't think this variable will be resolved. In order to use the shared libraries in Plastic, we need to follow the steps from this other thread (Mikael Kalms comment).

 

Quote

 

You should be able to repro this by setting up an empty Plastic repo as your Global Shared Library, and another Plastic repo containing a single-line Jenkinsfile:

    @Library('JenkinsBuildScripts@latest') _

 

Then you would set up two Jenkins jobs referencing the latter repo. 

 

_20181226_180508.JPG

 

You can see that the shared library is not configured via enviroment variable in the selector. We can arrange a GoToMeeting to show you this feature in one of our machines.

Regards,

Carlos.

Share this post


Link to post
Share on other sites

I tryed the same setup with GitHub and it didn't work either. It just checkout the latest changeset. So it looks like some bug in Jenkins.

 

I added 2 different libraries that point to a different branches of the same repository. So now i can't use "Load implicitly" setting, but i can switch shared library on certain jobs to development branch.

Share this post


Link to post
Share on other sites

Hi Evgeny,

I've run the following test today:

1. Create the shared library in the Jenkins configuration:

image.png

2. I created new Pipeline type build with the following content:

 

image.png

 

3. This is the content of the Jenkins file I use in the repo. I set the shared library:

 

image.png

4- I run the build and it's succesful. I cannot reproduce any error.

Regards,

Carlos.

Share this post


Link to post
Share on other sites

Yes, in that case all works well.

But how do you select library varsion that way?

For example:

@Library('myrepo@development') _
@Library('myrepo@v1.0') _
@Library('myrepo@stable') _
etc

 

Share this post


Link to post
Share on other sites

Hi,

I'm including @Mikael Kalms in this thread as I know they are using shared libraries.

I've seen the following in the documentation:

https://tomd.xyz/jenkins-shared-library/

 

Quote

 

Hi, How to configure the JSL with different versions in Jenkins, Eg. @Library(JSL_1@1.0) _ instead of master in the version part, need to use git tags. @Library(JSL_1@master) _ Any idea?

 

version is depend on git branch name. More info can check this out https://jenkins.io/doc/book/pipeline/shared-libraries/#library-versions

 

Regards, 
Carlos.

Share this post


Link to post
Share on other sites

I read this article before. In case of git - it works with tags and only if you use "Modern scm". There are no options for Plastic in "Modern scm".

And in "Legacy scm" you only option is to use "${library.Default.version}". And it didn't work even in GIT.

Share this post


Link to post
Share on other sites

In order to select a library version, using the branch name doesn't work as they propose in the previous link?

 

Quote

 

When using the library step you may also specify a version:


library 'my-shared-library@master'

Since this is a regular step, that version could be computed rather than a constant as with the annotation; for example:


library "my-shared-library@$BRANCH_NAME"

 

 

Regards,

Ct'arlos.

Share this post


Link to post
Share on other sites

As i said earlier - i solved my problem by defining 2 different libraries in Jenkins Settings. I'm ok with this workaround. So we can close this topic :)

 
In case, you want to investigate this further:
version selection doesn't work as they propose in the previous link for legacy SCM. I tested it with:
- Plastic - returns errors in selector
- Github (legacy SCM) - just checksout latest changeset (regardless of brunch)
 
I didn't find any references to someone using library versions on legacy SCM and decided that this is a Jenkins bug, but i didn't created issue on their bug tracker
 
 
  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...