0

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.

JCDani
  • 307
  • 7
  • 20
  • Pool here should define machine which is used to deploy/compile your package/code not the machine where you suppose to deploy. Yoy may try to achieve this, but the original purpose is different. And not evrywhere you can use template expressions, because it has to be known at compilation and not on runtime. – Krzysztof Madej Sep 20 '21 at 09:12

2 Answers2

2

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.

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
0

Below yaml works.

variables:
  vmname: machinename
pool:
  name: poolname
  demands:
    - agent.name -equals $(vmname)
Bowman Zhu-MSFT
  • 4,776
  • 1
  • 9
  • 10