Interview Prep/Jenkins/Jenkinsfile syntax, Groovy & CPS errors

A library class call fails with `unable to resolve class com.devopsshack.ImageTag`

IntermediateTroubleshootingJenkinsfile syntax, Groovy & CPS errors
Answer

Likely causes → Library not loaded before the import, wrong package path (src/com/devopsshack/ImageTag.groovy must declare package com.devopsshack), library loaded with the dynamic library step (no compile-time import), or a typo.

Diagnose → Check the log for Loading library shack-lib@v1 and browse the library tag for the file path.

Fix → Use @Library('shack-lib@v1') import com.devopsshack.ImageTag at the top, align package declaration and folders, or access via library('shack-lib@v1').com.devopsshack.ImageTag.

Prevent → JenkinsPipelineUnit tests that load classes from src/.

All Jenkins questions Roadmap: Jenkins

More on Jenkinsfile syntax, Groovy & CPS errors