我正在尝试使用任务 FileTransform 来修改 grafana json 模板的值。它可以通过以下方式修改 somes 键的值:
- task: FileTransform@2
displayName: "Transform Jsons"
inputs:
folderPath: 'metrics/dashboards/**/'
xmlTransformationRules: ''
jsonTargetFiles: '**/*.json'
并用要替换的键声明变量:
templating.list.0.query: $(azureClusterName)
templating.list.0.current.text: $(azureClusterName)
templating.list.0.current.value: $(azureClusterName)
templating.list.0.options.0.text: $(azureClusterName)
templating.list.0.options.0.value: $(azureClusterName)
如果在 jsonTargetFiles 我只声明一个文件它可以完美运行,但我想知道如何为具有相同键的文件分配不同的值。
我试过使用“replaceTokens”,并在 jsons 文件中有不同的变量名:
- task: replacetokens@3
displayName: 'Replace tokens'
inputs:
rootDirectory: 'metrics/dashboards'
targetFiles: '**/*.json'
encoding: 'auto'
verbosity: 'detailed'
actionOnMissing: 'fail'
tokenPrefix: '#{'
tokenSuffix: '}#'
但是使用替换标记,grafana 中的模板不起作用,即使它说值已被正确替换。
最好的