下午好,我在這裏滾動,閱讀問題,並嘗試使用不同的代碼來獲取構建以及它們的所有定義,但是,每當我嘗試執行代碼並獲取構建定義時,它都不會返回任何內容,即使我確定知道那裏有成功和失敗的構建。但是我什麼也沒得到。TFS獲取全部構建定義
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();
}
}
我使用VS2017社區版
原來getAllTeamProjects返回它們的0。 –
此API只適用於XAML構建定義,如果您使用的是構建vNext(TFS 2015+中的缺省構建),則必須使用REST API。 – DaveShaw