无发布管道中的Azure XML转换

时间:2020-10-25 13:26:47

标签: xml azure azure-pipelines azure-pipelines-yaml

在普通的Azure管道(没有发布)中,基于输入参数,我想编辑管道中使用的XML文件。例如,如果需要,我想更改日志级别。接下来,文件将由az storage file upload

加载
- task: myTask@1
  displayName: 'Upload Config File'
  inputs:
    scriptLocation: 'inlineScript'
    inlineScript: |
      myConfiguration="${{ parameters.name }}-configuration.xml"
      # here want to modify the xml above
      az storage file upload --share-name $(config-file-share) \
                            --source "$(input-files-path)/${myConfiguration}"

阅读后 Azure File transforms and variable substitution reference 我有点迷路了... 我可以在没有发布管道的情况下使用它吗?但是,如果可以的话,我不知道该如何应用...很难做到这一点。例。 我认为更简单的方法就是使用awk。

能否请您分享自己的看法和例子?

1 个答案:

答案 0 :(得分:0)

我可以在没有发布管道的情况下使用它吗?

当然。您可以在普通的Azure管道中进行操作。

但是当替换xml文件的值时,您需要使用变量,因此需要将参数的值转换为变量的值。

您可以使用Replace token extension中的Replace Tokens task

这里是一个例子:

XML文件:

enter image description here

Yaml样本:

parameters:
  - name: test
    type: string
    default: aa
variables:
   - name: a
     value: ${{ parameters.test }}

pool:
  vmImage: 'ubuntu-latest'

steps:
- script: echo $(a)
  displayName: 'Run a one-line script'

- task: replacetokens@3
  inputs:
    rootDirectory: '$(build.sourcesdirectory)'
    targetFiles: '**/*.xml'
    encoding: 'auto'
    writeBOM: true
    actionOnMissing: 'warn'
    keepToken: false
    tokenPrefix: '#{'
    tokenSuffix: '}#'
    useLegacyPattern: false
    enableTelemetry: true

参数输入值:changevalue

结果:

enter image description here

顺便说一句,您也可以使用the file transform task。该任务是通过文件转换变量。