jenkins-groovy-scripting-best-practices
Jenkins Groovy Scripting Best Practices
Purpose
Jenkins Pipeline (both per-repo Jenkinsfiles and shared libraries) is
written in Groovy, but it does not run like ordinary Groovy: it executes
under the Groovy sandbox (a security boundary that blocks arbitrary
Java/Groovy method calls unless explicitly approved) and under CPS
(Continuation-Passing Style) transformation (so pipelines can pause/
resume across Jenkins restarts), both of which produce failure modes that
look like bugs in your code but are actually artifacts of the execution
model. This skill covers the sandbox/script-approval workflow, how to unit
test shared library Groovy without a running Jenkins controller, and the
specific Groovy/CPS pitfalls (closures capturing this, non-serializable
state, @NonCPS usage) that recur in pipeline code.