Jenkins Pipeline NotSerializableException: groovy.json.internal.LazyMap

后端 未结 12 786
长发绾君心
长发绾君心 2020-11-27 03:08

Solved: Thanks to below answer from S.Richmond. I needed to unset all stored maps of the groovy.json.internal.LazyMap type whi

12条回答
  •  不知归路
    2020-11-27 03:26

    I found more easy way in off docs for Jenkins pipeline

    Work example

    import groovy.json.JsonSlurperClassic 
    
    
    @NonCPS
    def jsonParse(def json) {
        new groovy.json.JsonSlurperClassic().parseText(json)
    }
    
    @NonCPS
    def jobs(list) {
        list
            .grep { it.value == true  }
            .collect { [ name : it.key.toString(),
                          branch : it.value.toString() ] }
    
    }
    
    node {
        def params = jsonParse(env.choice_app)
        def forBuild = jobs(params)
    }
    

    Due to limitations in Workflow - i.e., JENKINS-26481 - it's not really possible to use Groovy closures or syntax that depends on closures, so you can't > do the Groovy standard of using .collectEntries on a list and generating the steps as values for the resulting entries. You also can't use the standard > Java syntax for For loops - i.e., "for (String s: strings)" - and instead have to use old school counter-based for loops.

提交回复
热议问题