Is it possible to combine multiple shared Jenkins libraries?
E.g. I have a common shared library: my-shared-library (git repository with a maven project) defined on a jenkins folder that contains some jobs. Each job that runs inside that folder can use that shared library in the Jenkinsfile with:
@Library("my-shared-library") _
import com.pipelines.Pipeline
new Pipeline().build()
Now I would like to create another shared library: my-specialized-shared-library that contains a few specialized pipelines (in another git repository also as a maven project). Pipelines (groovy classes, scripts etc) in my-specialized-shared-library should be able to use/import classes, pipelines etc from: my-shared-library is that possible and if so what are the recommended approach?
In Manage Jenkins > Configure System I defined 2 different Global Pipeline Libraries from different URLs.
The .jenkinsfile:
@Library('GlobalLibrary-1@some_branch') l1 //you can write here _ (underscore) or any other string.
@Library('GlobalLibrary-2@any_branch') l2
import com.lib1.Class1; // import from GlobalLibrary-1 (Jenkins automatically finds com.lib.Class1 inside GlobalLibrary-1)
import com.prodcode.Class2; // import from GlobalLibrary-2 (Jenkins automatically finds com.prodcode.Class2 inside GlobalLibrary-2)
node {
new Class1();
new Class2();
}
I can even use imports inside Class2.groovy to get classes from GlobalLibrary-1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With