我在本地安装了TFS 2015 RC2.我正在尝试使用REST API在vNext定义中对构建进行排队.
我正在使用来自VSO的代码示例稍作修改(主要是更改URL和身份验证方法以使用内部部署TFS).
我正在使用两个REST API调用.
第一个是:GET http:// mytfssrv:8080/tfs/DefaultCollection/myproject/_apis/build/definitions /
返回所有指定的项目构建定义:ID为1的构建定义,这是一个XAML构建定义我不想排队并使用ID 2构建定义,这是vNext构建定义 - 这就是II想要对我的构建进行排队的地方
请注意,我省略了?api-version = 1.0部分 - 因为如果我不这样做,我只获得XAML构建定义.
第二个调用是在vNext构建定义中对新构建进行排队:
POST http:// mytfssrv:8080/tfs/DefaultCollection/myptoject/_apis/build/requests?api-version = 1.0
以下数据:
{"definition":{"id":**2**},"reason":"Manual","priority":"Normal","queuePosition":0,"queueTime":"0001-01-01T00:00:00","requestedBy":null,"id":0,"status":null,"url":null,"builds":null}
Run Code Online (Sandbox Code Playgroud)
我从服务器得到的响应是:
TF215016:构建定义2不存在.指定有效的构建定义,然后重试.
我尝试更改API版本,以各种方式更改发布数据但从未成功.
知道如何从DID中治愈TFS吗?
TFS 2015 RC2使用新的API(版本2.0-preview.2).我在问题中提到的VSO样本已经过时,并且在您希望对新构建进行排队时不相关.
目前,没有文档,但Web门户使用REST API,所以只是Fiddler.
这是代码:
var buildRequestPOSTData =
new BuildRequest()
{
Definition = new Definition()
{
Id = firstBuildDefinition.Id
},
Project = new Project { Id = "project guid" },
Queue = new Queue { Id = 1 },
Reason = 1,
sourceBranch = "$Branch"
};
responseBody = await QueueBuildAsync(client, buildRequestPOSTData, _baseUrl + "build/Builds");
Run Code Online (Sandbox Code Playgroud)
以下是具有构建请求的新参数的类:
public class BuildRequest
{
[JsonProperty(PropertyName = "definition")]
public Definition Definition { get; set; }
[JsonProperty(PropertyName = "demands")]
public string Demands { get; set; }
[JsonProperty(PropertyName = "parameters")]
public IEnumerable<string> Parameters { get; set; }
[JsonProperty(PropertyName = "project")]
public Project Project { get; set; }
[JsonProperty(PropertyName = "queue")]
public Queue Queue { get; set; }
[JsonProperty(PropertyName = "reason")]
public int Reason { get; set; }
[JsonProperty(PropertyName = "sourceBranch")]
public string sourceBranch { get; set; }
[JsonProperty(PropertyName = "sourceVersion")]
public string RequestedBy { get; set; }
}
public class Definition
{
[JsonProperty(PropertyName = "id")]
public int Id { get; set; }
}
public class Queue
{
[JsonProperty(PropertyName = "id")]
public int Id { get; set; }
}
public class Project
{
[JsonProperty(PropertyName = "id")]
public string Id { get; set; }
}
Run Code Online (Sandbox Code Playgroud)