Add/remove 使用 REST 检查管道 API

Add/remove pipeline checks using REST API

我需要在 Azure DevOps 管道环境中动态 add/remove 或启用禁用批准和检查。 这个有休息吗api?

目前不支持。您可以给功能请求投票以表达您的兴趣 here

Is there a rest api for this?

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

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

这里给大家总结一下。

用于add/delete审批和检查环境的api是:

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

add or delete对应的api方法PostDELETE.


首先,为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.
}

2)添加任务检查Azure functionInvoke 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. Just check the task.json文件中找到对应的task id

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}

希望这些对您有所帮助。