5
votes

We have an Azure DevOps Server (on prem) and different build/release pipelines.

A build/release is depending to other systems. Now if we plan to do maintenance work on this other systems, no Azure build/release pipeline should be run during this time because of the dependency of this systems. We can go to every pipeline and set the pipeline to "pause". This is working well for a small numbers of build/release pipelines, but if we have a lot of pipelines this would be time-consuming to enabled-disable all pipelines.

Is there any way to pause/resume all Azure Pipelines at the same time? (e.g. TeamCity has a simple flag to pause/resume the whole queue).

I checked the API, but there is also no way to disable the queue itself (change setting on the build/release pipeline). It this would be possible, we could loop through every pipeline definition and pause/resume the queue.

1
You might want to look at the Definition Update API, and play with the queueStatus attribute in the request body. There's an option to set the definition as paused, AFAICS. Never tried it myself, though.Yan Sklyarenko
@YanSklyarenko you're right, the queueStatus it what you need @Christian, if the value is 1 so the pipeline is disabled.Shayki Abramczyk
Depending on whether you are using deployment group agents or not on the release, it will be a little more involved for release pipelines, since I don't believe you can pause those on the definition. You could disable them on the agent, but if they are deployment group agents you might have to do something with security to prevent deployments.Matt

1 Answers

4
votes

You can disable the agents to prevent the pipeline from running.

Go the Agent Pools under Pipelines in Project settings-->Select the agent pool -->Go to Agents tab-->Disable all the agents.

enter image description here

You can also use rest api to pause the build pipeline mentioned in the comments. See below example in powershell scripts: See here to get a personal access token.

$PAT="Personal Access Token"

$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)"))

#list build definiations api
$url = "https://dev.azure.com/org/proj/_apis/build/definitions?api-version=6.1-preview.7"

#list all build definitions
$AllDefinitons = Invoke-RestMethod -Uri $url1 -Headers @{Authorization = ("Bearer {0}" -f $base64AuthInfo)} -Method get

#get all the definition ids
$Ids = $AllDefinitons.value | select id

foreach($id in $Ids){
 
   $definitionUrl="https://dev.azure.com/org/proj/_apis/build/definitions/$($id.id)?api-version=6.1-preview.7"

   #get the definition of each build pipeline
   $definiton = Invoke-RestMethod -Uri $definitionUrl-Headers @{Authorization = ("Bearer {0}" -f $base64AuthInfo)} -Method get

   #set queueStatus to paused
   $definiton.queueStatus= "paused"

   #update the definition
   Invoke-RestMethod -Uri $definitionUrl-Headers @{Authorization = ("Basic {0}" -f $base64AuthInfo)} -Method put -Body (ConvertTo-Json $definiton-Depth 100) -ContentType "application/json"

}