In my pipeline, I want to load a shared library. I read the official documentation but I have a problem. When using the annotation
@Library, I don’t have any problem but when using the step
library, I cannot get my Pipeline to work.
- CloudBees Jenkins Enterprise - Managed Master (CJEMM)
- CloudBees Jenkins Enterprise- Operations Center (CJEOC)
- CloudBees Jenkins Team (CJT)
- CloudBees Jenkins Platform - Client Master (CJPCM)
- CloudBees Jenkins Platform - Operations Center (CJPOC)
When trying to load a shared library into a Pipeline, you can use both
@Library annotation on the import, or the
library step. However, they don’t behave exactly the same way.
@Library will use the ClassLoader of the Pipeline to load the classes that you want to use in your Pipeline Script.
When you are using the step
library, it doesn’t use the ClassLoader. So it has to guess whether you are loading a class or a package. If you are not following the Java Naming Convention, this can be problematic. For example, with:
def lib = library('foo').bar
it will assume that
bar is a package name in the
In the end, it is important to follow the Java convention when naming your shared library classes.
- Official documentation: https://jenkins.io/doc/book/pipeline/shared-libraries/#loading-libraries-dynamically