What goes in `src/` and how is it used?
IntermediateConceptShared libraries
Answer
src/ holds Groovy classes on a standard package path, imported from pipelines or vars/ files.
// src/com/devopsshack/ImageTag.groovy
package com.devopsshack
class ImageTag implements Serializable {
static String forBranch(String branch, String sha) {
"${branch.replaceAll('[^a-zA-Z0-9_.-]', '-')}-${sha.take(7)}"
}
}
@Library('shack-lib@v1') import com.devopsshack.ImageTag
def tag = ImageTag.forBranch(env.BRANCH_NAME, env.GIT_COMMIT)
Classes that need to call steps must receive the script object (this) and call script.sh(...).
More on Shared libraries
What is the directory structure of a shared library?BeginnerHow does a `vars/` global step work?BeginnerHow do classes in `src/` call pipeline steps?IntermediateWhat is `libraryResource` used for?IntermediateWhat are the ways to load a library in a Jenkinsfile?IntermediateGlobal vs folder-level vs ad hoc libraries: what is the security difference?Advanced