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.
Multiple triggers can kick off a single pipeline.
A parallel job is what runs a pipeline job and one parallel job is required to execute one pipeline job. Azure DevOps gives one parallel job to every organization for free. Private projects have a build time limit of 1800 minutes or 30 hours, it also can only run one pipeline job at a time.
Pipelines concurrency defines how many pipelines can run simultaneously. When more pipelines than your plan allows are running, the subsequent executions will be enqueued, waiting for all previously triggered pipelines to finish. The number of concurrent pipelines is determined per workspace.
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://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema#triggers
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.
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.
Preventing concurrent runs may be done by setting up an environment with an Exclusive Lock check. That allows working with Microsoft-hosted agents, not just self-hosted agents. It also does not require pipelines to be assigned to specific agents the way Demands do.
In Pipelines/Environments define an environment, say "my_environment".
To the environment add a check of type "Exclusive Lock".
In your YAML, reference environment "my_environment" using this form:
lockBehavior: sequential stages: - stage: Stage jobs: - deployment: Job environment: my_environment strategy: runOnce: deploy: steps: ...
This will force multiple queues of the same pipeline to run sequentially in queue order. Different pipelines must use different environments, otherwise they will block each other.
More information here: https://learn.microsoft.com/en-us/azure/devops/release-notes/2021/sprint-190-update#azure-pipelines-1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With