I need to parse 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 it?
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 -> switch(obj.name) { case "foo": doAThing(obj) break case "bar": doAnotherThing(obj) break } } }
In the above example, even with a json object, for example:
[{ "name": "foo" }, { "name": "bar" }]
... the pipeline always exits after the first iteration. This is probably due to synchronization and asynchronous functions. Is there any way to do this?
source share