Good afternoon, I was scrolling here, reading questions and trying different code on how to get builds and all the definitions from them, however, whenever I try to execute code and get builds definitions it returns nothing, even though I for sure know there are both successful and unsuccessful builds in there. However I get nothing.
private static void Main(string[] args)
{
NetworkCredential credential = new NetworkCredential("MyUsername", "MyPassword");
VssBasicCredential basicCred = new VssBasicCredential(credential);
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("https://tomheza.visualstudio.com/DefaultCollection"), basicCred);
tpc.Authenticate();
CatalogNode catalogNode = tpc.CatalogNode;
ReadOnlyCollection<CatalogNode> collectionNodes = tpc.CatalogNode.QueryChildren(new[] { CatalogResourceTypes.TeamProject }, false, CatalogQueryOptions.None);
foreach (CatalogNode collectionNode in collectionNodes)
{
Console.WriteLine(collectionNode.Resource.DisplayName);
}
var buildServer = (IBuildServer)tpc.GetService(typeof(IBuildServer));
var vcs = tpc.GetService<VersionControlServer>();
var teamProjects = vcs.GetAllTeamProjects(true);
foreach (TeamProject proj in teamProjects)
{
var defs = buildServer.QueryBuildDefinitions(proj.Name);
Console.WriteLine(string.Format("Team Project: {0}", proj.Name));
foreach (IBuildDefinition def in defs)
{
IBuildDetailSpec spec = buildServer.CreateBuildDetailSpec(proj.Name, def.Name);
spec.MaxBuildsPerDefinition = 1;
spec.QueryOrder = BuildQueryOrder.FinishTimeDescending;
var builds = buildServer.QueryBuilds(spec);
if (builds.Builds.Length > 0)
{
var buildDetail = builds.Builds[0];
Console.WriteLine(string.Format(" {0} - {1} - {2}", def.Name, buildDetail.Status.ToString(), buildDetail.FinishTime));
}
}
Console.WriteLine();
}
}
I am using VS2017 community version
Like the comment said above, the VNext build definition information couldn't be reached using the old version API. Install this TFS ExtendedClient Nuget package for your project, using the method below to get all build definitions.
You could also use this kind of REST API to get build definitions: