9
votes

I am have 2 build agents and 8 pipelines in azure devops. If a run starts for pipeline A, and another run is triggered for the same pipeline Azure Devops will start a second run on the other agent without waiting for the first to finish.

How do I make Azure Devops wait until the first run is finished before starting the second one?

Edit: using yaml pipelines rather than old build/release pipelines.

2
Why does it matter to you? Builds should be stateless.Daniel Mann
It's common in other CI such as jenkins to run end to end tests against a test environment before deploying to the next environment in the pipeline. So you want to prevent another version being deployed over this one until the pipeline as finished.cfbd
That would happen in a release pipeline, not a build. Releases have mechanisms to control the degree of parallelism.Daniel Mann
I'm using the new yaml pipelines rather than old build/release pipelinescfbd
There is a community request for this feature that you can vote on: developercommunity.visualstudio.com/idea/365730/….Matt Thalman

2 Answers

3
votes

I think you can use adding demands to the pool on the agent job of pipelines, so that it will run with one same agent because of the same specified condition.

First, add one Capability in the agent.

enter image description here

And then, in your YAML, add demands to the pool.

pool:
  name: {agent pool name}
  demands: Limit -equals DisAbleParallel 

The format of it is demands:{CapabilityName} -equals {CapabilityValue}.

While you specified the agent demands, the pipeline will just run with this agent. While A is running, the second one will not run at same time because the previous is running, the agent is being using. So that, the second one will run until previous ends.

5
votes

Looks like you can do this by using the trigger options in the yaml file:

trigger:  
    batch: true

Do note that this value is false by default (so when left empty), but it might only be when a trigger has been defined?

Docs here: https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema#triggers