0
votes

I am to implement pre-deployment gates on my azure devops release. I am using HTTP request gate to check each time if there is ongoing deployment. The problem is, when deployment on one release finishes (stage 1 ), I want to prevent the deployment on next release in queue if there is (stage 2) to the pipeline that does not do deployment for example.

The end goal is, no matter how many releases in queue I have and no matter how many agents in my pool, I want to make sure that release start only if there is no other active release in deployment/other stages.

1
Please show your code to show what you have tried so far.Connell.O'Donnell
i am using azure devops gates UI , no code envolved.Vladi Pikovski

1 Answers

0
votes

You can add a gate of Invoke REST API: GET to call below Deployments - List rest api and check if there are any releases in deployment. See below steps:

https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/deployments?operationStatus=queued,queuedForAgent,phaseInProgress&api-version=6.1-preview.2

1, Add a Invoke Rest Api Gate

Go to Pre-deployment conditions --> Enable Gate-->Add a Invoke Rest Api Gate-->Click Manage to create a service connection. See below screenshot.

enter image description here

2, Create a service connection shown in above screenshot.

When you Click Manage in above screenshot. You will be forward to service connections page. Click new service connection and select Generic type of service connection:

enter image description here

3, Go back to the Invoke Rest Api Gate. Select the service connection just created: See below

  • Method: Get
  • URL suffix and parameters: /_apis/release/deployments?operationStatus=queued,queuedForAgent,phaseInProgress&api-version=6.1-preview.2
  • Success criteria: eq(root['value'][0], '')

enter image description here

Above Invoke rest api gate will call the deployments list rest api to filter these releases that are inProgress or queued of deployment using operationStatus filter(ie. operationStatus=queued,queuedForAgent,phaseInProgress). If the there is any deloyment is inProgress or queued the Success criteria: eq(root['value'][0], '') will failed.

If you using self-hosted agents and Environments. You can check the Exclusive lock on Environments and Agent pools.