Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure DevOps Server - pause/resume all pipelines during maintenance window

Tags:

azure-devops

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.

like image 592
Christian Bumann Avatar asked Sep 14 '20 07:09

Christian Bumann


1 Answers

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"

}
like image 124
Levi Lu-MSFT Avatar answered Nov 25 '22 21:11

Levi Lu-MSFT