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

`expected to call java.util.ArrayList.each but wound up catching org.jenkinsci.plugins.workflow.cps.CpsClosure2.call; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/`

AdvancedTroubleshootingJenkinsfile syntax, Groovy & CPS errors
Answer

Likely causes → A CPS-transformed closure is called from non-CPS code: e.g. a closure passed to a Java method, toString() override, constructor or @NonCPS method invoking a CPS closure.

Diagnose → Find the call site from the stack trace; check for closures passed to sort, Comparator, inject, or used inside @NonCPS methods.

Fix → Replace with a plain for loop in CPS code, or make the whole helper @NonCPS without calling steps inside.

Prevent → Keep @NonCPS helpers pure (no steps, no CPS closures).

All Jenkins questions Roadmap: Jenkins

More on Jenkinsfile syntax, Groovy & CPS errors