Interview Prep/Jenkins/Shared libraries

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(...).

All Jenkins questions Roadmap: Jenkins

More on Shared libraries