使用 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