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.

All CI/CD questions

More on Jenkins