Solution skill
Jenkins: LazyMap from JSON parsing throws NotSerializableException in pipelines
Complete solution
If a Jenkins pipeline dies with NotSerializableException naming LazyMap, the JSON you parsed is the problem.
Jenkins: LazyMap from JSON parsing throws NotSerializableException in pipelines
TL;DR
If a Jenkins pipeline dies with NotSerializableException naming LazyMap, the JSON you parsed is the problem. Convert it to plain maps and lists, or do the parsing in a @NonCPS method, before the value crosses a pipeline checkpoint. Context: From a Jenkins community forum thread.
Use this when you run into the situation in the title.
When not to use this skill: unrelated tasks. It covers only the procedure above.
Compatibility
The steps above apply to the commands named in them. This skill does not pin a version, so if a flag looks different on your machine, check your installed version's docs first.
Details
Parsing JSON in a pipeline and stashing the result in a variable throws NotSerializableException mentioning YOUR_HOST.LazyMap. The map the JSON parser hands back is lazy and not serializable, and pipeline CPS checkpoints require everything in scope to serialize. The fix discussed: convert to a plain serializable structure (or parse inside a @NonCPS method) before crossing a checkpoint.
Evidence
Source: From a Jenkins community forum thread. Parsing JSON in a pipeline and stashing the result in a variable throws NotSerializableException mentioning groovy.json.internal.LazyMap. The map the JSON parser hands back is lazy and not serializable, and pipeline CPS checkpoints require everything in scope to serialize. The fix discussed: convert to a plain serializable structure (or parse inside a @NonCPS method) before crossing a checkpoint.
Verified resolution: If a Jenkins pipeline dies with NotSerializableException naming LazyMap, the JSON you parsed is the problem. Convert it to plain maps and lists, or do the parsing in a @NonCPS method, before the value crosses a pipeline checkpoint.
Source URL: https://community.jenkins.io/t/jenkins-notserializableexception-groovy-json-internal-lazymap/13489
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_kqnK3lNLsC7zexL9Caiizg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Jenkins: LazyMap from JSON parsing throws NotSerializableException in pipelines <span>— Vectle</span></a>