BuildDefinition null

雨燕双飞 提交于 2019-12-10 18:48:40

问题


I'm using this piece of code to determine the build definition details of a specific build:

TfsTeamProjectCollection tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tfsUri);
IBuildServer buildServer = (IBuildServer)tpc.GetService(typeof(IBuildServer));
IBuildDetail bd = buildServer.GetBuild(buildUri);
string a = bd.BuildDefinition.Name;

If the tfsUri and buildUri are pointing to a TFS2013 server and a TFS2013 build then the code is ok but if I change to TFS2015 server + build (vNext build) then the bd.BuildDefinition object becomes null.

How can I get the build details (build definition) of a vNext build using C# TFS API?


回答1:


I'm guessing that the TFS API you're using doesn't support Build vNext, you are probably going to have to try using the REST API.

You can use this to get the Build Definitions:

https://{your-project}.visualstudio.com/defaultcollection/taeguk/_apis/build/definitions?api-version=2.0

The once you have the "ID" you can use this call:

https://{your-project}.visualstudio.com/defaultcollection/taeguk/_apis/build/builds?api-version=2.0&definitions={id}

I'm basing this on what I've found on the Visual Studio Team Services REST API docs.




回答2:


Your question is very similar to this post here which I have answered. However, since you interest is in the build definition rather than the individual build, the code would need an alteration as such:

var definitions = buildClient.GetDefinitionsAsync(project: "<projectname>");
foreach (var definition in definitions.Result)
    {
        Console.WriteLine(definition.Name);
    }


来源:https://stackoverflow.com/questions/32353000/builddefinition-null

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!