gpt4 book ai didi

azure-devops - 使用 REST API 添加/删除管道检查

转载 作者:行者123 更新时间:2023-12-02 00:03:20 25 4
gpt4 key购买 nike

我需要在 Azure DevOps 管道环境中动态添加/删除或启用禁用批准和检查。是否有用于此的 rest api?

enter image description here

最佳答案

Is there a rest api for this?

是的,它有。但是,正如@Krysztof 所说,截至今天,我们还没有向公众提供此类 api 文档。这是因为您正在寻找的是一项仅支持 YAML 管道的功能(从 environments 配置 Check and approval ),直到现在, 我们正在开发但不发布相应的 rest api (for YAML) 文档。

但是,作为解决方法,您可以通过 F12 捕获这些 API。只需从 UI 执行操作,然后捕获和分析相应的 api 记录以找出您的期望。

这里给大家总结一下。

用于添加/删除审批和检查环境的api是:

https://dev.azure.com/{org name}/{project name}/_apis/pipelines/checks/configurations

添加或删除对应的api方法PostDELETE


首先,为您分享批准和检查添加的请求正文示例。

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.
}

2) 添加任务检查Azure函数调用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
}

在这个请求体中,你可以从我们的public source code中找到对应的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"
}
}

在此主体中,如果模板源来自githubbitbucket,则repositoryName 的值应为{org name}/{repos name}

希望这些对您有所帮助。

关于azure-devops - 使用 REST API 添加/删除管道检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61471634/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com