Jenkinsfile write JSON file
Got it!
script { def someMap = [ 'name' : "john", 'surname' : "doe" ] def json = new groovy.json.JsonBuilder() json "people": someMap def file = new File("$WORKSPACE/people.json") file.write(groovy.json.JsonOutput.prettyPrint(json.toString())) }
You can use writeJSON
: Write JSON to a file in the workspace.
If you don't want to use any plugin, there is a workaround with the core Jenkins method writeFile
e.g.:
writeFile( file: "foo/bar.json", text: """\ { 'a': 'x', 'b': 'y' } """.stripIndent())