Reputation: 133
How do I write my ADO YAML in such a way that there might be demands such as Agent.Name = 'abc' that might be needed occasionally while queuing the build? An example is if we want to investigate a build failure that is happening on a specific build agent Another use case is if there is a software upgrade such as .NET core and we want to test our build on the upgraded software on one agent before we upgrade the software on all the build agents
Classic pipelines had the ability to add demands without updating the pipeline.
Upvotes: 0
Views: 2299
Reputation: 31
The problem is that ADO cannot read parameters in the same "stage" they are defined. So to get around that I ended up creating jobs and reading the parameter there. In this case it would look something like this:
parameters:
# Define a parameter
- name: demand
displayName: Demand
type: string
default: DefaultPool
values:
- DefaultPool
- SpecialSoftware
jobs:
- job: My pipeline job
pool:
name: My_Pool
demands: ${{ parameters.demand }}
steps:
- script: echo Hello, world!
displayName: 'Run a one-line script'
Upvotes: 0
Reputation: 4730
You can create a YAML Pipeline in Azure DevOps and use parameter to tweak the demands:
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- main
parameters:
# Define a parameter
- name: demand
displayName: Demand
type: string
default: DefaultPool
values:
- DefaultPool
- SpecialSoftware
variables:
demand: '${{ parameters.demand }}'
pool:
vmImage: ubuntu-latest
# Use the variable
${{ if ne(variables['demand'], '') }}:
demands: ${{variables.demand}}
steps:
- script: echo Hello, world!
displayName: 'Run a one-line script'
When you want to manually run the pipeline, you can choose the value for the demand
parameter:
Documentation:
Upvotes: 0