Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure devops API POST未应用于Azure DevOps服务器的分支机构(2019年更新1)_Azure Devops_Azure Devops Rest Api - Fatal编程技术网

Azure devops API POST未应用于Azure DevOps服务器的分支机构(2019年更新1)

Azure devops API POST未应用于Azure DevOps服务器的分支机构(2019年更新1),azure-devops,azure-devops-rest-api,Azure Devops,Azure Devops Rest Api,我对Azure DevOps API帖子感到困惑。我已成功为“最少审阅者数”创建了策略,但没有针对我指定的分支创建该策略。我已经在Fiddler中完成了这项工作,下面是我的请求(私有值混淆): 以下是回应机构: { "createdBy": { "displayName": "Surname, Firstname", "url": "http://our-tfs-server:8080/tfs/TheCollection/_apis/Identities/SomeString

我对Azure DevOps API帖子感到困惑。我已成功为“最少审阅者数”创建了策略,但没有针对我指定的分支创建该策略。我已经在Fiddler中完成了这项工作,下面是我的请求(私有值混淆):

以下是回应机构:

{
  "createdBy": {
    "displayName": "Surname, Firstname",
    "url": "http://our-tfs-server:8080/tfs/TheCollection/_apis/Identities/SomeString",
    "_links": { "avatar": { "href": "http://our-tfs-server:8080/tfs/TheCollection/_apis/GraphProfile/MemberAvatars/win.SomeString" } },
    "id": "7b40f8ab-a933-4b43-bdf8-bf0b179d28e6",
    "uniqueName": "MyUsername",
    "imageUrl": "http://our-tfs-server:8080/tfs/TheCollection/_api/_common/identityImage?id=SomeString",
    "descriptor": "win.SomeOtherString"
  },
  "createdDate": "2020-01-23T02:09:34.4738854",
  "isEnabled": true,
  "isBlocking": true,
  "isDeleted": false,
  "settings": {
    "minimumApproverCount": 2,
    "creatorVoteCounts": false,
    "allowDownvotes": false,
    "resetOnSourcePush": false,
    "scope": [ { "repositoryId": "7718333c-044e-423a-baa1-45e6a1f0ff41" } ]
  },
  "_links": {
    "self": { "href": "http://our-tfs-server:8080/tfs/TheCollection/8b7e65ed-1136-4b0f-9780-de2a3860447a/_apis/policy/configurations/254" },
    "policyType": { "href": "http://our-tfs-server:8080/tfs/TheCollection/8b7e65ed-1136-4b0f-9780-de2a3860447a/_apis/policy/types/fa4e907d-c16b-4a4c-9dfa-4906e5d171dd" }
  },
  "revision": 1,
  "id": 254,
  "url": "http://our-tfs-server:8080/tfs/TheCollection/8b7e65ed-1136-4b0f-9780-de2a3860447a/_apis/policy/configurations/254",
  "type": {
    "id": "fa4e907d-c16b-4a4c-9dfa-4906e5d171dd",
    "url": "http://our-tfs-server:8080/tfs/TheCollection/8b7e65ed-1136-4b0f-9780-de2a3860447a/_apis/policy/types/fa4e907d-c16b-4a4c-9dfa-4906e5d171dd",
    "displayName": "Minimum number of reviewers"
  }
}
请注意,
“scope”:[{“repositoryId”:“7718333c-044e-423a-baa1-45e6a1f0ff41”}]
仅包含repositoryId

在分支机构策略的UI中,未勾选“最少审阅者数量”选项,并且在完整存储库级别没有问题的版本。如果我调用
/\u api/policy/configurations
,那么我会看到新策略,因此它已经被创建。也许现在这将使用该策略保护所有分支,但我们不希望在全局级别使用它,并且由于DevOps web ui中没有用于此策略的工具,我非常确定它无论如何也不会是这样


那么,这是API运行方式中的一个疏忽,还是应用策略配置的分支使用另一种技术设置的?

因此…答案在于json请求主体上属性名称的大写。虽然json不区分大小写,并且我发出的请求在内部返回了200和一个有效的主体,但服务器在应用策略配置的分支设置上出现了问题。NewtonSoft在开始时用大写字母序列化属性名称,我发现使用小写字母修复了原始问题,然后创建的返回对象分配了refName和matchKind,并勾选了MinimumNumberOfReviewers复选框,数字设置为2。为什么MS只能序列化一个或两个属性有点奇怪,至少我全局应用了JsonSerializationSettings,以避免在任何地方添加JsonPropertyAttribute以及忽略空属性的需要。

为什么不能使用UI手动将策略应用到分支级别,然后进行查看,然后参考结果,看看帖子的主体应该是什么样子?自从发帖以来,我一直在运行Fiddler并接受它的请求。我不完全清楚是哪种财产引起了这个问题。我一次一次从请求中删除默认值属性,然后删除以查看返回的内容。困扰我的是,我需要从一个C#应用程序中驱动这个程序来批量应用规则,我觉得这个调用看起来很正确,但从我提出与Fiddler捕获的请求相同的应用程序中,它失败了。我会继续努力的。除了请求主体上的内容,我似乎没有遗漏任何东西。谢谢
{
  "createdBy": {
    "displayName": "Surname, Firstname",
    "url": "http://our-tfs-server:8080/tfs/TheCollection/_apis/Identities/SomeString",
    "_links": { "avatar": { "href": "http://our-tfs-server:8080/tfs/TheCollection/_apis/GraphProfile/MemberAvatars/win.SomeString" } },
    "id": "7b40f8ab-a933-4b43-bdf8-bf0b179d28e6",
    "uniqueName": "MyUsername",
    "imageUrl": "http://our-tfs-server:8080/tfs/TheCollection/_api/_common/identityImage?id=SomeString",
    "descriptor": "win.SomeOtherString"
  },
  "createdDate": "2020-01-23T02:09:34.4738854",
  "isEnabled": true,
  "isBlocking": true,
  "isDeleted": false,
  "settings": {
    "minimumApproverCount": 2,
    "creatorVoteCounts": false,
    "allowDownvotes": false,
    "resetOnSourcePush": false,
    "scope": [ { "repositoryId": "7718333c-044e-423a-baa1-45e6a1f0ff41" } ]
  },
  "_links": {
    "self": { "href": "http://our-tfs-server:8080/tfs/TheCollection/8b7e65ed-1136-4b0f-9780-de2a3860447a/_apis/policy/configurations/254" },
    "policyType": { "href": "http://our-tfs-server:8080/tfs/TheCollection/8b7e65ed-1136-4b0f-9780-de2a3860447a/_apis/policy/types/fa4e907d-c16b-4a4c-9dfa-4906e5d171dd" }
  },
  "revision": 1,
  "id": 254,
  "url": "http://our-tfs-server:8080/tfs/TheCollection/8b7e65ed-1136-4b0f-9780-de2a3860447a/_apis/policy/configurations/254",
  "type": {
    "id": "fa4e907d-c16b-4a4c-9dfa-4906e5d171dd",
    "url": "http://our-tfs-server:8080/tfs/TheCollection/8b7e65ed-1136-4b0f-9780-de2a3860447a/_apis/policy/types/fa4e907d-c16b-4a4c-9dfa-4906e5d171dd",
    "displayName": "Minimum number of reviewers"
  }
}