Azure 构建管道:如何将“多行变量”传递给构建模板?

use*_*186 7 azure azure-devops azure-pipelines

我有这个 Azure 构建管道,它启动 VSTest 任务。它应该测试以“Unittest.csproj”结尾的所有项目,但应排除以“Common.Unittest.csproj”结尾的测试项目:

# my-azure-pipeline.yaml:

...
steps:
- task: VSTest@2
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
      **/*Unittest.csproj
      ! **/*Common.Unittest.csproj
...
Run Code Online (Sandbox Code Playgroud)

这很好用。

由于我有几个类似的构建,我想提取一个构建模板 (myTemplate.yaml),它现在使用变量 $(testprojects) 作为值“testAssemblyVer2”:

# myTemplate.yaml

...
steps:
- task: VSTest@2
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: $(testProjects)
...
Run Code Online (Sandbox Code Playgroud)

现在我尝试像这样设置变量,但没有成功:

# my-azure-pipeline.yaml

...
variables:
  - testProjects: |
      **/FistUnittestProject.csproj
      ! **/SecondUnittestProject.csproj
    
extends:
  template: myTemplate.yaml
...
Run Code Online (Sandbox Code Playgroud)

我想知道通过变量定义“多行事物”的正确方法是什么?

任何帮助表示赞赏。

Jan*_*SFT 2

但是,截至目前,不支持在 Azure DevOps 中创建多行变量。您可以对该用户的声音进行投票。如果该提案获得足够的票数,微软产品团队将认真考虑该提案。

作为替代方法,您可以使用 PowerShell 任务输出换行符来设置多行变量。

详细步骤请参考这个答案。我已经测试过它并且工作完美。