简体   繁体   中英

Azure Build Pipeline: How to pass a "multiline variable" to a build template?

I have this Azure build pipeline, which starts a VSTest Task. It should test all projects that end with "Unittest.csproj", but it should exclude test projects that end with "Common.Unittest.csproj":

# my-azure-pipeline.yaml:

...
steps:
- task: VSTest@2
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
      **/*Unittest.csproj
      ! **/*Common.Unittest.csproj
...

This works fine.

As I have a couple of similar builds, I want to extract a build template (myTemplate.yaml), which now uses a variable $(testprojects) for value "testAssemblyVer2":

# myTemplate.yaml

...
steps:
- task: VSTest@2
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: $(testProjects)
...

Now I tried to set the variable like this, but no luck:

# my-azure-pipeline.yaml

...
variables:
  - testProjects: |
      **/FistUnittestProject.csproj
      ! **/SecondUnittestProject.csproj
    
extends:
  template: myTemplate.yaml
...

I wonder which is the proper way to define a "multiline thing" via a variable?

Any help appreciated.

As of this time, however, creating multiline variables in Azure DevOps is not supported. You can vote on this user voice . The Microsoft product team will seriously consider the proposal, if it gets enough votes.

As an alternative method, you can use PowerShell task to output a line break to set a multiline variable.

For detailed steps, please refer to this answer . I have tested it and it works perfectly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM