我正在使用此处记录的管道 REST 端点来创建管道并将其与 YAML 文件关联。在我的一些管道上,我想禁用持续集成。在 DevOps 门户上,您可以在此处执行此操作:
我想将其自动化作为我的流程的一部分,但我在官方文档中没有看到任何内容。
当我检查从 UI 发送的有效负载时,我尝试通过在调用 Pipelines - Create 端点时向有效负载中的配置属性添加一个空触发器数组来传递我看到的门户正在执行的操作,但这似乎被忽略.:
"triggers":[]
这是一个完整的有效负载示例:
{
"configuration": {
"variables": {
"VARIABLE_NAME": {
"isSecret": false,
"value": "Value"
}
},
"type": "yaml",
"path": "azure-pipelines.yml",
"repository": {
"id": "repo-id",
"type": "azureReposGit",
"name": "repo-name"
},
"triggers": []
},
"name": "Production"
}
有没有办法通过 REST API 覆盖/禁用 YAML 文件上的 CI 设置,还是只能通过 UI 实现?
根据Krzysztof Madej的这个SO线程回答,您需要使用Update Definition API和将queueStatus的值设置为Disabled。或者使用Create Definiton API并设置的值队列状态为已禁用。 定义API参考- 定义 - REST API(Azure DevOps 构建)|微软学习
由于创建/获取管道API在输出中不包含queueStatus值,请参阅下面:-
Powershell代码:-
API 参考 - 管道 - 获取 - REST API(Azure DevOps 管道)|微软学习
$PAT = "xxxxxxxxxa4gzoia"
$OrgName = "sid24desai0738"
$ProjectName = "AzureDevops"
$ApiVersion = "7.0"
# Retrieve pipelines information
$pipelines = Invoke-RestMethod -Uri "https://dev.azure.com/$OrgName/$ProjectName/_apis/pipelines/257?api-version=7.1-preview.1" -Method Get -Headers @{Authorization=("Basic {0}" -f [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$PAT")))}
# Output pipelines information
$pipelines
输出:-
您可以通过从上面Definiton API参考链接调用获取定义API来检查queueStatus[Get]:-
Powershell代码:-
$PAT = "hxxxxxxxxwa4gzoia"
$Organization = "sid24desai0738"
$Project = "AzureDevops"
$ApiVersion = "7.1-preview.7"
# Construct the URI
$Uri = "https://dev.azure.com/$Organization/$Project/_apis/build/definitions?api-version=$ApiVersion"
# Make the GET request to retrieve build definitions
$response = Invoke-RestMethod -Uri $Uri -Method Get -Headers @{
Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$PAT"))
}
# Output the response
$response.value
输出:-