-1

In AzureDevops yaml pipeline, can we define multiple node pools to the same stage. For example we have vm [vmpool] based and docker [dockerpool] based build agents and they are belongs to separate pools. But Some our pipeline stages can be run in any of these pools and where as some pipelines stages need to be run specific pools. So looking for a way to multiple nodepools for the stages where we can run in both the pools. Secondly, ca we define the precedence to the stages like, first need to check the available vms in the vmpool, if no vms are free to schedule, then schedul the dockerpool.

By going through the docs, I couldn't find any helpful information on this.

Vowneee
  • 956
  • 10
  • 33

1 Answers1

0

You can use template for each pool if across multiple pools in azure pipelines. A single step can be defined in one file and used multiple places in another file. Please refer to doc: step.template

For example:

# File: steps/build.yml

steps:
- script: npm install
- script: npm test

Across multiple pools:

# File: azure-pipeline.yml

stages:
- stage : stage1
  jobs:
  - job: run_in_pool_1
    pool:
      name: vmpool
    steps:
     - template: steps/build.yml # Template reference
  - job: run_in_pool_2
    pool:
      name: dockerpool
    steps:
     - template: steps/build.yml # Template reference

If you want to define the precedence to the stages like : check the available vms in the vmpool, you can use demand command to make sure the capabilities of agents.Please refer to:Demands

for example:

pool:
  name: MyPool
  demands:
  - myCustomCapability   # exists check for myCustomCapability
  - Agent.Version -equals 2.144.0 # equals check for Agent.Version 2.144.0

Dou Xu-MSFT
  • 880
  • 1
  • 1
  • 4
  • our requirement is not to segregate jobs or stage between pools, but to use multiple pools to the existing stages and define precedence to one pool among them and if that pool is occupied, take the other one .. – Vowneee Dec 07 '22 at 08:52
  • Sorry for misunderstanding. I'm afraid that there is no out of box function to achieve it. But you can write script by yourself to get all agents list and determine the state of agent by REST API :https://learn.microsoft.com/en-us/rest/api/azure/devops/distributedtask/agents/list?view=azure-devops-rest-6.0 – Dou Xu-MSFT Dec 09 '22 at 01:30
  • @Vowneee Does this meet your need? – Dou Xu-MSFT Dec 13 '22 at 08:04