我们有一个 Azure DevOps 服务器(本地)和不同的构建/发布管道。
构建/发布取决于其他系统。现在,如果我们计划在其他系统上进行维护工作,由于此系统的依赖性,在此期间不应运行 Azure 构建/发布管道。我们可以转到每个管道并将管道设置为“暂停”。这对于少量构建/发布管道运行良好,但如果我们有很多管道,启用/禁用所有管道将非常耗时。
有什么办法可以同时暂停/恢复所有 Azure Pipelines?(例如 TeamCity 有一个简单的标志来暂停/恢复整个队列)。
我检查了 API,但也无法禁用队列本身(更改构建/发布管道上的设置)。如果这是可能的,我们可以遍历每个管道定义并暂停/恢复队列。
您可以禁用代理以阻止管道运行。
转到项目设置中管道下的代理池--> 选择代理池 --> 转到代理选项卡 -->禁用所有代理。
您还可以使用rest api来暂停评论中提到的构建管道。请参阅 powershell 脚本中的以下示例:请参阅此处获取个人访问令牌。
$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"
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
945 次 |
最近记录: |