What are the ways to load a library in a Jenkinsfile?
IntermediateConceptShared libraries
Answer
@Library('shack-lib') _ // default version
@Library('[email protected]') _ // tag
@Library(['shack-lib@v1', 'sec-lib@main']) _ // several
@Library('shack-lib@v1') import com.devopsshack.ImageTag
library 'shack-lib@v1' // dynamic step, at runtime
library identifier: 'adhoc@main', retriever: modernSCM([$class: 'GitSCMSource', remote: 'https://github.com/org/adhoc-lib.git'])
The _ is needed because an annotation must annotate something. Libraries marked implicit load automatically without any annotation.
More on Shared libraries
What is the directory structure of a shared library?BeginnerHow does a `vars/` global step work?BeginnerWhat goes in `src/` and how is it used?IntermediateHow do classes in `src/` call pipeline steps?IntermediateWhat is `libraryResource` used for?IntermediateGlobal vs folder-level vs ad hoc libraries: what is the security difference?Advanced