azure-devopsazure-pipelinesazure-pipelines-yamlazure-yaml-pipelines

How to parameterize azure agent.name in azure pipeline?


I am trying to parameterize the agent.name in azure pipeline. The objective is to give the user the option to deploy the code in the desired machine. So I have created a pool with a few machines in it and parameterize the agent.name

Code

parameters
- name: machinename
  displayName: machinename
  type: string
  values:
  - 10.72.1.123
  - 10.72.1.124

pool:
  name: PoolA
  demands:
    - agent.name -equals ${{ parameters.machinename}}

Error : When trying to run the above code , I get the below error.

A template expression is not allowed in this context

Please help in resolving this issue.


Solution

  • You may try to use this workaround:

    trigger: none
    
    pool:
      name: Default
      demands:
      - agent.name -equals $(machinename)
    
    jobs:
    - job:
      displayName: 'Job 1'
      steps:
      - task: Bash@3
        inputs:
          targetType: 'inline' 
          script: |
            echo "$(machinename)"
    
    

    then please define pipeline variable (on editing pipeline):

    enter image description here

    Make this variable available of overwriting:

    enter image description here

    and then n running pipeline:

    enter image description here

    enter image description here

    You will not get dropdown list, but this is the only way to overcome this issue.