Jenkins Groovy how to call methods from @NonCPS method without ending pipeline
<p>I need to parse some JSON in a Jenkins Pipeline and call some regular methods in a loop, however the script always exits after the first function call. How to do this?</p>

<pre><code>import groovy.json.JsonSlurper
import com.cloudbees.groovy.cps.NonCPS

@NonCPS
def myMethod(String json) {
    def jsonSlurper = new JsonSlurper()
    def jsonObject = jsonSlurper(json)
    jsonObject.each {
        obj -&gt;
            switch(obj.name) {
                case "foo":
                    doAThing(obj)
                    break
                case "bar":
                    doAnotherThing(obj)
                    break
            }
    }
}
</code></pre>

<p>In the above example, even with a json object like: </p>

<pre><code>[{
    "name": "foo"
}, {
    "name": "bar"
}]
</code></pre>

<p>...the pipeline always exits after the first iteration. This is presumably due to mixing sync and async functions. Is there any way to do this?</p>