当前位置: 首页 > 工具软件 > LazyMap > 使用案例 >

Jenkins pipeline groovy.json.internal.LazyMap

葛哲彦
2023-12-01

错误原因是因为使用 `` 导致的。
具体根源解释为:

Since Groovy 2.3 (note: Jenkins 2.7.1 uses Groovy 2.4.7) JsonSlurper returns LazyMap instead of HashMap. This makes new implementation of JsonSlurper not thread safe and not serializable. This makes it unusable outside of @NonDSL functions in pipeline DSL scripts.

However you can fall-back to groovy.json.JsonSlurperClassic which supports old behavior and could be safely used within pipeline scripts.

解决方法使用 JsonSlurperClassic 代替 JsonSlurper ,示例:

@NonCPS
def jsonParse(def json) {
    new groovy.json.JsonSlurperClassic().parseText(json) // 重点
}

node('master') {
    def config =  jsonParse(readFile("config.json"))
    ...
}

(END)

 类似资料:

相关阅读

相关文章

相关问答