San*_*eev 2 azure-devops azure-pipelines azure-devops-rest-api
我需要在 azure DevOps 管道环境中动态添加/删除或启用禁用批准和检查。有没有这个的rest api?
有没有这个的rest api?
是的,确实如此。但是,正如 @Krysztof 所说,截至今天我们还没有向公众提供此类 api 文档。这是因为您正在寻找的是一项仅支持 YAML 管道的功能(Check and approval从进行配置environments) ,而到目前为止,我们正在开发但没有发布相应的 REST API (用于 YAML)文档。
但是,作为解决方法,您可以从F12捕获这些 api 。只需从 UI 执行操作,然后捕获并分析相应的 api 记录即可找出您所期望的内容。
这里我给大家做一下总结。
用于添加/删除审批和检查环境的API是:
https://dev.azure.com/{org name}/{project name}/_apis/pipelines/checks/configurations
Run Code Online (Sandbox Code Playgroud)
对应的api方法是add or delete和Post。DELETE
approval and check 首先,向您分享添加的请求正文示例。
1)在此环境中添加审批:
{
"type": {
"id": "8C6F20A7-A545-4486-9777-F762FAFE0D4D", // The fixed value for Approval
"name": "Approval"
},
"settings": {
"approvers": [
{
"id": "f3c88b9a-b49f-4126-a4fe-3c99ecbf6303" // User Id
}
],
"executionOrder": 1,
"instructions": "",
"blockedApprovers": [],
"minRequiredApprovers": 0,
"requesterCannotBeApprover": false // The pipeline requester allow to approve it.
},
"resource": {
"type": "environment",
"id": "1", // Environment id
"name": "Deployment" //Environment name
},
"timeout": 43200 // Set the available time(30d) of this approval pending. The measure unit is seconds.
}
Run Code Online (Sandbox Code Playgroud)
2)添加任务检查、Azure function任务Invoke rest api等:
{
"type": {
"id": "fe1de3ee-a436-41b4-bb20-f6eb4cb879a7", // Fixed value if you want to add task check
"name": "Task Check" //Fixed value
},
"settings": {
"definitionRef": {
"id": "537fdb7a-a601-4537-aa70-92645a2b5ce4", //task Id
"name": "AzureFunction", //task name
"version": "1.0.10" //task version
},
"displayName": "Invoke Azure Function", //task display name configured
"inputs": {
"method": "POST",
"waitForCompletion": "false",
"function": "csdgsdgsa",
"key": "436467543756" // These are all task inputs
},
"retryInterval": 5, // The re-try time specified.
"linkedVariableGroup": "AzKeyGroup"// The variable group name this task linked with
},
"resource": {
"type": "environment",
"id": "2",
"name": "Development"
},
"timeout": 43200
}
Run Code Online (Sandbox Code Playgroud)
task id在此请求正文中,您可以从我们的公共源代码中找到相应的内容。只需检查task.json相应任务的文件即可。
3)添加模板检查:
{
"type": {
"id": "4020E66E-B0F3-47E1-BC88-48F3CC59B5F3", // Fixed value for template check added.
"name": "ExtendsCheck" //Fixed value
},
"settings": {
"extendsChecks": [
{
"repositoryType": "git", // github for Github source, bitbucket for Bitbucket source
"repositoryName": "MonnoPro",
"repositoryRef": "refs/heads/master",
"templatePath": "tem.yml"
}
]
},
"resource": {
"type": "environment",
"id": "6",
"name": "development"
}
}
Run Code Online (Sandbox Code Playgroud)
在本正文中,如果模板源来自github或bitbucket,则repositoryName 的值应为{org name}/{repos name}。
希望这些有帮助。
| 归档时间: |
|
| 查看次数: |
1500 次 |
| 最近记录: |