How to parameterize agent pool name in azure pipeline with yaml file

Viewed 3022

Hi I am using agent pool in azure pipeline, so i have multiple agents so i want to parameterize the pool name like shown below but when i do this i get an error as (Line: 11, Col: 9): A template expression is not allowed in this context

parameters:
  - name: pool_name
    displayName: agent pool location
    type: string
    default: test-ashish

trigger:
- none

pool:
  name: ${{parameters.pool_name}}
  demands: 
  - Location -equals EASTUS2

steps:
- script: |
    echo "This job is only for testing"
    echo $()
  name: Test_Job
  displayName: Test Job
1 Answers

This issue can be solved by using the answer in this issue: Azure Devops: Is it possible to nest yaml templates inside another yaml template?.

Copyed from link: refer code:

parameters:
  buildArtifactName: "build"
  solution: ""

jobs:
- job: 'BuildSolution'
  pool:
    vmImage: ${{parameters.vmImage}}
    continueOnError: false
  variables:
    artifactName: ${{ parameters.buildArtifactName}}
  steps:
    - task: NuGetCommand@2
      displayName: 'Restore NuGet packages'
      inputs:
        restoreSolution: ${{ parameters.solutionDir }}/${{ parameters.solution }}
        configuration: ${{parameters.buildConfiguration}}
Related