I am facing this error Caused: java.io.NotSerializableException: groovy.json.JsonBuilder
while building a jenkins pipeline. However the same code is working in jenkins scriptler
. Should I do any changes on this code to write a Json file through jenkins pipeline
def vars = ["a": 1,"b": 2,"c": 3,"d": 4,]
def json = new groovy.json.JsonBuilder()
def final_out = json "sample": vars
json "file": final_out
def file = new File("/tmp/sample.json")
file.write(groovy.json.JsonOutput.prettyPrint(json.toString()))
Sample output looks like:
{
"file": {
"sample": {
"a": 1,
"b": 2,
"c": 3,
"d": 4
}
}
}