`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).
More on Jenkinsfile syntax, Groovy & CPS errors
`WorkflowScript: 1: Missing required section "agent" @ line 1, column 1.`Beginner`Unknown stage section "step". Starting with version 0.5, steps in a stage must be in a ‘steps’ block.`Beginner`java.lang.NoSuchMethodError: No such DSL method 'withSonarQubeEnv' found among steps [archive, bat, build, ...]`Beginner`java.io.NotSerializableException: java.util.regex.Matcher`Advanced`java.io.NotSerializableException: groovy.json.internal.LazyMap`Intermediate`org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method groovy.lang.GroovyObject invokeMethod java.lang.String java.lang.Object`Intermediate