Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a pipeline on a specifinc agent from a pool in Azure DevOPS

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?

like image 376
Fishman Avatar asked Oct 24 '25 16:10

Fishman


2 Answers

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.

enter image description here

I tested it works as I expected, you can check if it meets your needs.

like image 54
Leo Liu-MSFT Avatar answered Oct 26 '25 06:10

Leo Liu-MSFT


I left a comment illustrating this. However here is the offical documentation on how this would be configured.

like image 28
DreadedFrost Avatar answered Oct 26 '25 06:10

DreadedFrost