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