我想使用Jenkins管道解析JSON文件,并将一些值附加到我的Yaml文件中。以下是我的Json文件。
{
"id": "test",
"chef": {
"attributes": {
"example": {
"example": "test"
}
},
"run_list": [
"recipe[example::example]"
]
}
}
这是我的Yaml文件的样子:
id: example
components:
component1:
type: example1
data:
action:
first: FullClone
chef:
default: '{"example1": { "value1": "test123" }, "run_list": ["recipe[example1::example123"]}'
component2:
type: example2
这是我正在使用的流水线脚本:
pipeline {
agent any
stages {
stage {
stpes {
jsonData = readJSON file: 'test.json'
yamlData = readYaml file: 'test.yaml'
parsedJsonData = jsonData.chef
yamlData['components']['component1']['data']['chef']['default'] = "$parsedJsonData"
writeYaml file: 'newYaml.yaml', data: yamlData
sh "cat newYaml.yaml"
}
}
}
}
我得到的输出如下所示:
id: example
status: DR
components:
component1:
type: example1
data:
action:
first: FullClone
chef:
default: '[attributes:[example:[example:test]], run_list:[recipe[example::example]]]'
component2:
type: example2
但是我希望输出结果像这样:
id: example
components:
component1:
type: example1
data:
action:
first: FullClone
chef:
default: '{"example": { "example": "test" }, "run_list": ["recipe[example::example"]}'
component2:
type: example2