Jenkins Pipeline NotSerializableException: groovy.json.internal.LazyMap

后端 未结 12 735
长发绾君心
长发绾君心 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:46

    EDIT: As pointed out by @Sunvic in the comments, the below solution does not work as-is for JSON Arrays.

    I dealt with this by using JsonSlurper and then creating a new HashMap from the lazy results. HashMap is Serializable.

    I believe that this required whitelisting of both the new HashMap(Map) and the JsonSlurper.

    @NonCPS
    def parseJsonText(String jsonText) {
      final slurper = new JsonSlurper()
      return new HashMap<>(slurper.parseText(jsonText))
    }
    

    Overall, I would recommend just using the Pipeline Utility Steps plugin, as it has a readJSON step that can support either files in the workspace or text.

提交回复
热议问题