Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Devops disable concurrent runs on the same pipeline

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.

like image 905
cfbd Avatar asked Jun 27 '19 22:06

cfbd


People also ask

Can we have multiple triggers in same pipeline?

Multiple triggers can kick off a single pipeline.

What is parallelism in Azure DevOps?

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.

What is pipeline concurrency?

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.


3 Answers

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

like image 175
Rob Bos Avatar answered Nov 10 '22 04:11

Rob Bos


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.

like image 39
Mengdi Liang Avatar answered Nov 10 '22 03:11

Mengdi Liang


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.

  1. In Pipelines/Environments define an environment, say "my_environment". ADO nav bar image

  2. To the environment add a check of type "Exclusive Lock".

  3. 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

like image 1
Bruce Haley Avatar answered Nov 10 '22 02:11

Bruce Haley