在我的Jenkinsfile中,我正在尝试创建并将一个简单的JSON文件写入工作区文件夹。
JSON文件的内容应为:
{"people": {"name":"john","surname":"doe"}}
有什么想法吗?
在我的Jenkinsfile中,我正在尝试创建并将一个简单的JSON文件写入工作区文件夹。
JSON文件的内容应为:
{"people": {"name":"john","surname":"doe"}}
有什么想法吗?
明白了!
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()))
}
writeFile
进行解决,例如:writeFile(
file: "foo/bar.json",
text: """\
{
'a': 'x',
'b': 'y'
}
""".stripIndent()
)
writeJSON
:将JSON写入工作区中的文件。
JsonBuilder
可序列化吗?我认为所有的Groovy JSON类方法都是不可序列化的。这似乎会导致错误。 - Matt Schuchard