How to load a Jenkins shared library into another Jenkins shared library with branch and credentials?

44 Views Asked by At

In my Jenkins project, I have a library (i.e. a .groovy file in the /vars directory).

I need to load a shared library from a different github repo. In fact I need it from a specific branch of that repo, and it is a private repo that requires user authentication.

How can I do this?

1

There are 1 best solutions below

0
Ruslan On

You can use global jenkins configuration for libraries

https://www.jenkins.io/doc/book/pipeline/shared-libraries/#using-libraries

and define 2 libraries there. For private repo you will need to have credentials for github.

in Jenkinsfile you can use

@Library(['libA']) _

and in libA/vars/somepipeline.groovy

you need to write

library 'libB'

this line will load libB and you will be able to use code from library B in library A