Forum Discussion
Martines_01
Dec 05, 2023Copper Contributor
Azure DevOps - only one pipeline at the time
Hello everyone,
We want to run at our pipeline only one at the time. We are using exclusive lock and pipeline that is build from 4 different stages where only one has exclusive lock. After deployment we want to run next stage which is the last one including tests after deployment. After the tests will finish we want to run next pipeline. The issue is where we have in queue few jobs and I tried to add on deployment and tests exclusive lock the previous job will end deployment and next in queue which is waiting in lock for deployment should be done after tests that are also with exclusive lock but somehow azure is picking next job deployment and then is doing previous tests so it is getting duoplicated.
So, Is there a way to only run one pipeline at the time and every other in queue will wait till previous one will finish all the stages?
1 Reply
Sort By
Yes, this is possible:
- Use "Limit Concurrent Jobs" in Agent Pool
- Go to Project Settings → Agent Pools.
- Select the Self-hosted agent pool you're using.
- Set the maximum parallel jobs to 1 to enforce sequential execution.
- Use Deployment Job "Exclusive Lock" Correctly
- Since you’re using exclusive lock, Azure DevOps still allows jobs in the queue, but it does not strictly control their order.
- Instead, wrap everything (deployment and test stages) inside one deployment job so the lock applies to the full sequence.
- Use "Depends On" for Stage Order Enforcement
Modify your pipeline YAML to explicitly order execution:
stages: - stage: Deploy jobs: - deployment: DeployApp environment: 'Prod' strategy: runOnce: deploy: steps: - script: echo "Deploying App" - script: echo "Deployment complete" - stage: Tests dependsOn: Deploy # Ensures this stage runs AFTER deployment jobs: - job: RunTests steps: - script: echo "Running tests..." - script: echo "Tests completed"
- Use "Queue Behavior" to Ensure Sequential Execution
Inside the Agent Pool settings, use the option:
- Allow only one job to run at a time
- This will queue subsequent jobs until the previous pipeline fully finishes, preventing duplicates.