I'm having a problem retrieving build information from a Visual Studio Online project through the TFS API. I can connect to the project, it seems, and find the expected team project collection and team project, but despite the project having two build definitions and a number of builds, the TFS API always returns zero-length arrays to me when querying for build definitions or builds. The project is a Git project. My production code is similar to this test code I've written to attempt to debug the problem:
var tfsUri = new Uri("https://[my project].visualstudio.com");
var tcs = new TfsConfigurationServer(tfsUri);
var teamProjCollections = tcs
.CatalogNode
.QueryChildren(
new[] { CatalogResourceTypes.ProjectCollection },
false,
CatalogQueryOptions.None)
.Select(collectionNode => new Guid(collectionNode.Resource.Properties["InstanceId"]))
.Select(collectionId => tcs.GetTeamProjectCollection(collectionId));
var tpc = teamProjCollections
.Single(x => x.Name == @"[my project].visualstudio.comDefaultCollection");
var newTeamProjects = tpc
.CatalogNode
.QueryChildren(
new[] { CatalogResourceTypes.TeamProject },
false,
CatalogQueryOptions.None);
var tp = newTeamProjects
.Single(x => x.Resource.DisplayName == "[team project name]");
var buildServer = tpc.GetService<IBuildServer>();
var buildDefinitions = buildServer.QueryBuildDefinitions(tp.Resource.DisplayName);
buildDefinitions
is always an empty array. The build definitions are definitely there - I can connect to the project with Visual Studio, and it displays them in Builds tab of the Team Explorer. This code has worked for me in the past, however it was always TFVC projects I was connecting to, not a Git project. Interestingly, if I use a VersionControlServer
from the team project collection, like this:
var vcs = tpc.GetService<VersionControlServer>();
var teamProjects = vcs.GetAllTeamProjects(true);
..teamProjects
is always a zero-length array.
Also, if I try to get all builds for the team project collection by specifying a very general build detail spec, I get no builds returned.
Some additional information: I'm using VS Enterprise 2015 RC. I'm the administrator of the VSO project, and created the team project collection, the team project, and the build definitions. I've pushed some code, and run some builds. I'm logged in as myself when connecting through the API. My credentials appear to be correct.
So, in trying to figure this out, I have some questions. Do I need a different approach to accessing a Git repository? Perhaps it's only possible through the new TFS 2015 REST APIs? Perhaps I need to make my builds "visible" to myself in the VSO project?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…