0

So trying to checkout shared library by tag. This works perfectly with moderSCM, but for reasons we need to use other way (legacySCM);

def lib = library identifier: 'jenkins-shared-library@41', 
          retriever: legacySCM([$class: 'GitSCM', 
          userRemoteConfigs: [[credentialsId: 'account', 
         url: 'https://website.com.repo.git']]])

Doing that results to:

00:00:01.518  Loading library jenkins-shared-library@41
00:00:01.521  Selected Git installation does not exist. Using Default

However it does not checkout the tag "41". It just checkouts master. Why is the case?

1 Answer 1

0

I think it should work and I don't know why it isn't.

It is unusual for someone to load a shared library dynamically using the library step instead of using the @library annotation. Since you are specifying a retriever, why don't you pass the tag to it?

You can find out all the options for GitSCM by going to the snippet generator and trying the library step.

This is what I came up with:

library changelog: false, identifier: 'jenkins-shared-library', retriever: legacySCM([$class: 'GitSCM', branches: [[name: '41']], extensions: [], userRemoteConfigs: [[credentialsId: 'account', url: 'https://website.com.repo.git']]])

but I personally like to structure my code a bit more

final Object lib = library(
    [
        identifier: 'jenkins-shared-library',
        changelog: false,
        retriever: legacySCM(
            [
                $class: 'GitSCM',
                branches: [
                    [
                        name: '41'
                    ]
                ],
                extensions: [],
                userRemoteConfigs: [
                    [
                        credentialsId: 'account',
                        url: 'https://website.com.repo.git'
                    ]
                ]
            ]
        )
    ]
)

I hope that specifying the tag via the GitSCM works for you.

I think you should drop by https://community.jenkins.io/ and post about what you are trying to do in your pipeline. When you load a library dynamically because you lose one of the main benefits which is that shared libraries arent subjected to script security, at least when they are loaded via the @library annotation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.