We are using Azure DevOps for CI/CD of iOS applications. We provided mac machines with VMs on board and Azure DevOps agents are installed on these VMs.
Sometimes our pipelines fail due to agent VM instability. How to provide an option in the pipeline to run a job on a specific agent from the pool? It was easily achievable both in Jenkins and TeamCity. Here however we use YAML definitions for pipelines and seems that it is more tricky.
Would a parameter with a machine list along with capability condition in pipeline and capability defined in agents a way to go?
but keep in mind that: 1. I'd love to choose it while clicking "Run job", 2. List of available agents should be possible as a dropdown menu 3. By default it should use a random agent from pool
To achieve this in the YAML file, we could define two Runtime parameters, one of the parameter is used to select an specify agent from the dropdown list, one is used to decide whether to use a specific agent or the default a random agent.
in other words, we need use a parameter to select the demands and another parameter to disable/enable the previous demand. If we disable the previous demand, Azure devops will use a random agent by default.
I set following sample YAML file:
parameters:
- name: IfNeedDemands
type: boolean
default: False
- name: AgentSelect
displayName: Agent Select
type: string
values:
- VsAgent1
- VsAgent2
- VsAgent3
- VsAgent4
trigger: none
jobs:
- job: build
displayName: build
pool:
name: MyPrivateAgent
${{ if eq(parameters.IfNeedDemands, true) }}:
demands: Agent.Name -equals ${{ parameters.AgentSelect }}
steps:
- script: echo The value is ${{ parameters.AgentSelect }}
In above sample, parameter IfNeedDemands with syntax ${{ if eq(parameters.IfNeedDemands, true) }}: is used to determine the whether to enable demands.
Then the parameter AgentSelect used to select the private agent.

I tested it works as I expected, you can check if it meets your needs.
I left a comment illustrating this. However here is the offical documentation on how this would be configured.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With