Jenkinsfile write JSON file Jenkinsfile write JSON file jenkins jenkins

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()))        }


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())