Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple demands in Azure DevOps yaml template using parameters

I'm trying to figure out the syntax for specifying demands for a pool in a yaml template in Azure DevOps using parameters

So I have a template like this:

parameters:
  pool: ''
  demands: ''

jobs:
- job: 'Job1'
  pool:
    name: ${{parameters.pool}}
    demands: ${{parameters.demands}}

And calling it like:

- template: 'shared_pipeline.yml'
  parameters:
    pool: 'poolname'
    demands: >-
      FPGA -equals True
      CI -equals True

I've tried many different combinations like exchanging >- with |-

Changing demands: ${{parameters.demands}} to

demands: |
  - ${{parameters.demands}}

Since the original syntax for multiple demands is:

demands: |
  - FPGA -equals True
  - CI -equals True

But all the time I either get an error saying the syntax is wrong:

job_templates/shared_pipeline.yml (Line: 10, Col: 14): Invalid demand 'FPGA -equals True CI -equals True'. The demand should be in the format '<NAME>' to test existence, and '<NAME> -equals <VALUE>' to test for a specific value. For example, 'VISUALSTUDIO' or 'agent.os -equals Windows_NT'

or:

No agent found in pool pool which satisfies the specified demands:
     FPGA -equals True CI -equals True

And I've triple checked that there is and agent that has these capabilities.

It seems to me like the parameters are not getting.. expanded? correctly, like they're still on one line instead of one line each.

I've tried looking at the Azure DevOps documentation, but there are no examples of this kind of usage. I've tried googling, but couldn't find a solution

like image 551
DHummel Avatar asked Sep 14 '25 03:09

DHummel


1 Answers

So I actually gave up on this, but today I encountered the same-ish issue for dependsOn

There is a solution. Instead of calling the template like this:

- template: 'shared_pipeline.yml'
  parameters:
    pool: 'poolname'
    demands: >-
      FPGA -equals True
      CI -equals True

You call it like this:

- template: 'shared_pipeline.yml'
  parameters:
    pool: 'poolname'
    demands: ['FPGA -equals True', 'CI -equals True']

This is not documented anywhere in the documentation for Azure Pipelines.

Also the template should be updated to:

parameters:
  pool: ''
  demands: []

jobs:
- job: 'Job1'
  pool:
    name: ${{parameters.pool}}
    demands: ${{parameters.demands}}

To handle the case where demands is not given as an input argument. demands can be empty, but it should be an empty array and not an empty string. The same goes for dependsOn

like image 79
DHummel Avatar answered Sep 15 '25 21:09

DHummel