Azure Pipelines - 文件转换为具有相同密钥的不同文件设置不同的值

问题描述

我正在尝试使用 FileTransform 任务来修改 grafana json 模板的值。它可以通过以下方式修改某些键的值:

- 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 中的模板不起作用,即使它说值已被正确替换。

最佳

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)