Search code examples
jenkinsjenkins-pipelinejenkins-groovy

How to load vars files in Jenkins pipeline?


I have created several vars files to be used by one declarative pipeline. There is no src files required and they are working fine with the Load implicitly parameter of the Global Pipeline Libraries section checked. However, I want to know how to reference them in the pipeline to avoid them being loaded in other pipelines.

I tried using the @Library command in the pipeline, but I don´t know which name I must use, or if I need also to include the import commmand. I can´t find any examples or documentation to only load vars files without including shared libraries in the src folder. Is it possible?


Solution

  • It doesn't matter whether you have the src folder or not, you reference the global shared library the same way:

    @Library('my-shared-library') _
    

    The name here is the same name you gave it in the Name box under Manage Jenkins - System - Global Pipeline Libraries.