What is the CPS (Continuation Passing Style) execution model and why does it matter?
AdvancedConceptJenkins
Answer
Pipeline Groovy is transformed by the CPS engine so a running pipeline can be serialised to disk and survive a controller restart. Consequences: all local variables must be Serializable or you get java.io.NotSerializableException; some Groovy features (closures in .each, .collect, sort with comparators) behave oddly or fail; and CPS code runs slower than plain Groovy.
Mitigations: use @NonCPS on helper methods that need non-serialisable objects (they cannot call pipeline steps), prefer simple for loops over .each, and push heavy logic into shell scripts or a shared library class.
More on Jenkins
What is Jenkins and how is its architecture organised?BeginnerWhat are executors, nodes and labels in Jenkins?IntermediateWhy should you not run builds on the Jenkins controller?BeginnerHow do inbound (JNLP/WebSocket) and SSH agents connect to the controller?IntermediateWhat is a Jenkinsfile and where does it live?BeginnerDeclarative versus Scripted Pipeline: what are the differences?Intermediate