409 冲突响应使用 TFS 2015 REST API 排队构建

409 conflict response using TFS 2015 REST API to queue build

我有一个应用程序封装了与 TFS REST 的交互 API 以便对构建进行排队。该应用程序只是将所需的 json 发送到 API 并且它工作了几个月,直到它突然开始返回 409 - 冲突。

System.Net.WebException: The remote server returned an error: (409) Conflict. (https://tfs2015/tfs/spf/SPF/_apis/build/builds?api-version=2.0:{"definition":{"id":190},"parameters":"{}"})

w3.org 将 http 代码 409 定义为:

The request could not be completed due to a conflict with the current state of the resource. This code is only allowed in situations where it is expected that the user might be able to resolve the conflict and resubmit the request. The response body SHOULD include enough information for the user to recognize the source of the conflict. Ideally, the response entity would include enough information for the user or user agent to fix the problem; however, that might not be possible and is not required.

409 也不会消失 - 简单的重试总是失败。甚至整个 "have you tried switching it off an on again" 重新启动构建服务器的方法都没有帮助。

事实证明,"conflict"实际上并不是某种奇怪的并发问题,而是无法满足构建需求的状态。

基本上,正在排队的构建定义需要 "PowerShell = 4"。在构建服务器更新到 PowerShell 5 后,构建立即开始提供 409。

在这种情况下,409 意味着构建需求无法被池中的任何构建代理满足。

将构建定义更改为需要 PowerShell 而不是特定版本的 PowerShell 解决了该问题。

(如果我的应用程序将整个响应转储到控制台,我可以更快地解决这个问题,所以我会在不久的将来更新它)。