to queue upcoming builds until the current build and release is completed on azure

Mohammed Sadiq 1 Reputation point
2025-04-10T14:17:56.42+00:00

I have a build pipeline and a release process set up, with a version increment at the end of the release to ensure everything updates correctly. However, when new builds start while the current build/release process hasn’t finished, they use the old version.

What I want is to pause or queue any new builds until the ongoing build and release processes are complete.

Azure DevOps
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Bodapati Harish 320 Reputation points Microsoft External Staff
    2025-04-11T13:24:00.72+00:00

    Hello Mohammed Sadiq,

    To prevent new builds from starting while a build and release process is ongoing in Azure DevOps, ensuring the version increment is applied correctly, use one of these approaches:

    Approach 1: For YAML Pipelines (Recommended)

    Add this concurrency control block at the top of your YAML pipeline file to limit runs to one at a time:

    concurrency:
    
      group: version-control-group
    
      cancelInProgress: false
    

    Alternatively, for CI triggers, enable batch triggers:

    trigger:
    
      batch: true
    
      branches:
    
        include:
    
        - main
    

    Approach 2: For Classic Build and Release Pipelines

    • Build Pipeline:
      • Go to your build pipeline > Edit > Triggers > Continuous Integration.
      • Enable Batch changes ("Batch changes while a build is in progress").
      • Save.
    • Release Pipeline:
      • Go to your release pipeline > select environment (e.g., Dev, QA).
      • Click gear/settings icon > Enable Deployments do not run concurrently.
      • Save.

    Approach 3: Advanced Control with REST API

    Add a PowerShell task at the start of your pipeline to check for in-progress builds/releases:

    
    $token = "$(System.AccessToken)"
    
    $headers = @{ Authorization = "Bearer $token" }
    
    $org = "your-organization"
    
    $project = "your-project"
    
    # Check in-progress builds
    
    $buildUrl = "https://dev.azure.com/$org/$project/_apis/build/builds?statusFilter=inProgress&api-version=6.0"
    
    $buildResponse = Invoke-RestMethod -Uri $buildUrl -Headers $headers -Method Get
    
    # Check in-progress releases
    
    $releaseUrl = "https://vsrm.dev.azure.com/$org/$project/_apis/release/releases?statusFilter=inProgress&api-version=6.0"
    
    $releaseResponse = Invoke-RestMethod -Uri $releaseUrl -Headers $headers -Method Get
    
    if ($buildResponse.count -gt 0 -or $releaseResponse.count -gt 0) {
    
        Write-Host "Another build or release is in progress. Waiting..."
    
        Start-Sleep -Seconds 60
    
    } else {
    
        Write-Host "No active builds or releases. Proceeding..."
    
    }
    
    
    • Replace your-organization and your-project with your Azure DevOps details.
    • Add as a PowerShell task at the pipeline’s start.

    Note: Test in a non-production environment first.


    Hope this helps!

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.


  2. NGANDU-BISEBA Gabriel 35 Reputation points
    2025-04-15T07:41:40.7933333+00:00

    Use the batch triggers https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/azure-repos-git?view=azure-devops&tabs=yaml#batching-ci-runs

    Any new commit will be skipped until the current pipeline run completes. At which point the pipeline will run again for the latest commit after the completed run

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.