Run on specific self hosted servers using Azure pipelines

Viewed 491

In Azure git, I am running some self-hosted agents which live in the pool called "Default".

In an Azure pipeline (.yml file) I can tell the job that it has to run in a specific agent like this

pool:
  name: Default
  demands:
  - Agent.Name -equals MACHINE1

But what if I have, for example, 4 machines and I want it to run on machine 1 or 2 but not on machine 3 or 4?

I would have thought it would look something like this:

pool:
  name: Default
  demands:
  - Agent.Name -equals MACHINE1 -or MACHINE2

or maybe a wildcard:

pool:
  name: Default
  demands:
  - Agent.Name -equals MACHINE*

but neither of those work. Is there a way to do this?

1 Answers

Figured it out. You can do this by giving the servers different User-defined capabilities.

If you go to Project Settings > Agent pools > Default > Agents > (click on Agent) > Capabilities then you can add a Capability that for example is the same for MACHINE1 and MACHINE2 but different for MACHINE3 and MACHINE4.

Then you can test the capability in the pipeline and it will select only in the servers with that value set:

pool:
  name: Default
  demands:
    - MyVar -equals Group1
Related