1
votes

For example, consider the following template (named xyz.yml, for example):

parameters:
  projects: ['p1', 'p2', 'p3']

steps:
- ${{ each project in parameters.projects }}:
  - task: VSBuild@1
    displayName: Build ${{ project }}
    inputs:
      solution: ${{ project }}.sln
      ...

Now, suppose I have the following azure-pipelines.yml file:

...
steps:
  ...
  - template: xyz.yml
    parameters:
      projects: ???
...

How can I feed the projects template parameter from a build variable? Suppose at the time of the build I want to request building just p1 and p3. How can I do it?

2

2 Answers

1
votes

You could try to use stepList type parameter and pass the same parameter value to template.

For example:

main.yaml:

parameters:
  - name: mySteplist
    type: stepList
    default:
    - task: CmdLine@2
      inputs:
        script: |
          echo Write your commands here
          
          echo Hello world1
    - task: CmdLine@2
      inputs:
        script: |
          echo Write your commands here
          
          echo Hello world2

trigger:
  - none

steps:
  - template: stepstem.yml
    parameters: 
      buildSteps:
      - ${{ parameters.mySteplist }}
    
  # - template: stepstem.yml
  #   parameters:
  #     buildSteps:  
  #     - bash: echo Test #Passes
  #       displayName: succeed
  #     - bash: echo "Test"
  #       displayName: succeed
  # - ${{ parameters.mySteplist }}
  - task: CmdLine@2
    inputs:
      script: |
        echo Write your commands here
        
        echo Hello world3

stepstem.yaml:

parameters:
- name: buildSteps # the name of the parameter is buildSteps
  type: stepList # data type is StepList
  default: []

steps:
  - ${{ parameters.buildSteps }}
  - task: CmdLine@2
    inputs:
      script: |
        echo Write your commands here
        
        echo Hello world tem
  - script: echo "hello"

So, you could use VSBuild@1 tasks as default parameter value and could change it when queue build.

0
votes

Check the following example:

#xyz.yml

parameters:
  projects: []

steps:
- ${{ each project in parameters.projects }}:
  - task: VSBuild@1
    displayName: Build ${{ project }}
    inputs:
      solution: ${{ project }}.sln
      ...
      ...

#azure-pipelines.yml

 steps:
 - template: xyz.yml
   parameters:
     projects: ["p1", "p3"]