Azure Pipeline Matrix Strategy Variable Expansion 问题结合模板

Azure Pipeline Matrix Strategy Variable Expansion problem in conjunction with templates

对于 azp 中经常使用的任务,我创建了一个带有 yml 文件的自己的存储库,我将向您展示其中的一个子部分: 创建并上传-docu.yml:

parameters:
- name: Documentation
  type: string
  default: ''

- name: Language
  type: string
  default: ''

- name: ArchiveBaseDir
  type: string
  default: ''

steps:
- script: |
    ARCHIVERELPATH=${{parameters.Documentation}}-${{parameters.Language}}.zip
    ARCHIVEDIR=$(echo -n ${{parameters.ArchiveBaseDir}} | sed -e 's@/$@@')/${{parameters.Documentation}}/${{parameters.Language}}
    echo "##vso[task.setvariable variable=archiveRelPath;isOutput=true]$ARCHIVERELPATH"
    echo "##vso[task.setvariable variable=archiveDir;isOutput=true]$ARCHIVEDIR"
  name: ${{parameters.Documentation}}_${{parameters.Language}}_params

- task: DeleteFiles@1
  inputs:
    Contents: '$(Build.ArtifactStagingDirectory)/$(${{parameters.Documentation}}_${{parameters.Language}}_params.archiveRelPath)'

相关部分是:“脚本”的名称在作业中是唯一的 - 因此我可以使用这种扩展在模板中设置变量:

$(${{parameters.Documentation}}_${{parameters.Language}}_params.archiveRelPath)

只要我用固定值调用模板就可以正常工作,比如

- template: create-and-upload-docu.yml@templates
          parameters:
            Documentation: 'adocuvalue'
            Language: 'en_US'
            ArchiveBaseDir: '$(Build.ArtifactStagingDirectory)/build/'

但现在我想使用矩阵来制作一些包含几种语言的文档:

jobs:
  - job: Documentation_CI
    displayName: "Docu CI"
    timeoutInMinutes: 30
    strategy:
      matrix:
        main_en_US:
          Documentation: main
          Language: en_US
        main_de_AT:
          Documentation: main
          Language: de_AT
    steps:
      - checkout: self
      - template: create-and-upload-docu.yml@templates
          parameters:
            Documentation: ${{variables.Documentation}}
            Language: ${{variables.Language}}
            ArchiveBaseDir: '$(Ws)/build/'

但是在展开${{}}表达式的时候,好像还没有设置矩阵变量;这意味着模板脚本部分被调用 __params 并且管道有以下错误 Publishing build artifacts failed with an error: Input required: ArtifactName

有没有一种简单的方法来实现我想要的(能够在具有唯一命名模式的模板中设置一些变量):

附加信息:我们 运行 预置 Azure 2020。

Is there a somewhat simple way to achive what I want (being able to set some variables within templates with a unique naming schema):

对于给您带来的不便,我们深表歉意。

恐怕目前还没有这样的方法可以解决这个问题。

正如您测试的那样,${{}} 语法在编译时被解析。当我们在任务中将它用作名称或显示名称时,我们无法获取该值,因为它将在编译时进行解析。但是矩阵变量在编译时还没有设置。这就是我们得到值 _params.

的原因

有一个feature request about this. And you could add your request for this feature on our UserVoice site (https://developercommunity.visualstudio.com/content/idea/post.html?space=21 ),这是我们主要的产品建议论坛: