azure-devopsyamlazure-yaml-pipelines

Yaml based pipeline - setting the pool name at run time from the drop down


I have this yaml, how can I set the pool to the value selected in the drop down list? Obviously what I have now doesn't work. It complains that the template expression is not allowed in this context.

parameters:
- name: InstallNodeJS
  displayName: 'Install Node.js'
  type: boolean
  default: false

- name: AgentPoolSelector
  displayName: Select Agent Pool
  type: string
  default: Default
  values:
   - Default
   - Cloud
   - Dev Machines

variables:
  custom.branch: 'my-branch'
  
pool:
  name: $ {{ parameters.AgentPoolSelector }}

steps:
  - ${{ if eq(parameters.InstallNodeJS, true) }}:
     - template: templates/nodejs-install.yml

Solution

  • Per my test, to set the Pool name based on Runtime parameters we should insert the pool into one job/stage-level. You can try this format to resolve the issue:

    parameters:
    - name: InstallNodeJS
      displayName: 'Install Node.js'
      type: boolean
      default: false
    
    - name: AgentPoolSelector
      displayName: Select Agent Pool
      type: string
      default: Default
      values:
       - Default
       - Cloud
       - Dev Machines
    
    variables:
      custom.branch: 'my-branch'
      
    jobs:
    - job:
      displayName: FirstJob
      pool: 
        name: ${{ parameters.AgentPoolSelector }}
      steps:
        - ${{ if eq(parameters.InstallNodeJS, true) }}:
          - template: templates/nodejs-install.yml