3

I've got the following function in a workflow script that results in the error java.io.NotSerializableException: groovy.json.internal.LazyMap

def getParentTagForCurrentBranch(appWorkspace) {

   def parentTag = null

   dir("${appWorkspace.getPath()}") {

      parentTag = bat(script:"git describe --abbrev=0 --tags", returnStdout:true)
   }

   return parentTag
}

What I don't understand about the error is where I am using a LazyMap?

I've tried quite a few different variations of this block but all result in the error, I've also tried using the @NonCPS but that just results in the whole method being skipped.

Can anyone help me understand why this produces the error and how to resolve it?

StephenKing
  • 36,187
  • 11
  • 83
  • 112
user3617723
  • 1,355
  • 3
  • 17
  • 37
  • 1
    Are you sure you aren't parsing JSON somewhere else in the workflow? – tim_yates Sep 08 '16 at 16:04
  • If you can find where the JSON parsing is happening, this answer to another question may be helpful: http://stackoverflow.com/a/38439681/4142522 . I've found it to be the simplest way to work around the deficiencies of the default JsonSlurper without adding new dependencies. – BalRog Sep 08 '16 at 17:28

1 Answers1

2

Thanks the problem was with JsonSlurperswitching to JsonSlurperClassicdid the trick as mentioned here Jenkins Pipeline NotSerializableException: groovy.json.internal.LazyMap

Community
  • 1
  • 1
user3617723
  • 1,355
  • 3
  • 17
  • 37
  • 1
    So, FYI, I saw this today: `java.io.NotSerializableException: groovy.json.JsonSlurperClassic` – Michael Mol Jul 08 '19 at 17:56
  • Did you ever figure out how to prevent this? I just saw the same error, and I'm really confused. I was under the impression that using groovy.json.JsonSlurperClassic is the recommended solution for avoiding the Jenkins object serialization issue. So, if it's throwing a java.io.NotSerializableException on that class, I'm not sure what to do. – unbrokenrabbit Mar 23 '21 at 16:23
  • 1
    I also encountered this issue yesterday and fixed it by using readJSON instead of JsonSlurperClassic. https://www.jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#readjson-read-json-from-files-in-the-workspace – challett Mar 24 '21 at 18:27
  • @challett This should be actually the answer. Could you post it as one? I don't want to take your credits. – marverix Jul 20 '22 at 07:22