gpt4 book ai didi

c# - TFS API - 如何独立于它们属于哪个构建定义来查询构建

转载 作者:IT王子 更新时间:2023-10-29 04:40:49 24 4
gpt4 key购买 nike

IBuildServer.QueryBuilds(...) 的重载似乎不允许我这样做。

这是我的代码:

TfsTeamProjectCollection tfs = context.GetValue(TeamProject);
IBuildServer buildServer = (IBuildServer)tfs.GetService(typeof(IBuildServer));
buildServer.QueryBuilds( // **what should i put here?**

我不想指定构建定义,因为我想要的构建可能是任何类型。

这个问题看起来很简单,但谷歌搜索没有给我任何答案。

最佳答案

此代码将获取所有构建。 . .曾经

TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("http://tfs:8080"));

var vcs = tfs.GetService<VersionControlServer>();

var teamProjects = vcs.GetAllTeamProjects(true);

IBuildServer buildServer = (IBuildServer)tfs.GetService(typeof(IBuildServer));

foreach (TeamProject proj in teamProjects)
{
var builds = buildServer.QueryBuilds(proj.Name);

foreach (IBuildDetail build in builds)
{
var result = string.Format("Build {0}/{3} {4} - current status {1} - as of {2}",
build.BuildDefinition.Name,
build.Status.ToString(),
build.FinishTime,
build.LabelName,
Environment.NewLine);

System.Console.WriteLine(result);
}
}

但是,您可能对这段代码更感兴趣,它枚举每个团队项目并获取每个定义的最新构建状态:

TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("http://tfs:8080"));

var vcs = tfs.GetService<VersionControlServer>();

var teamProjects = vcs.GetAllTeamProjects(true);

IBuildServer buildServer = (IBuildServer)tfs.GetService(typeof(IBuildServer));

foreach (TeamProject proj in teamProjects)
{
var defs = buildServer.QueryBuildDefinitions(proj.Name);

System.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];

System.Console.WriteLine(string.Format(" {0} - {1} - {2}", def.Name, buildDetail.Status.ToString(), buildDetail.FinishTime));
}
}

System.Console.WriteLine();
}

关于c# - TFS API - 如何独立于它们属于哪个构建定义来查询构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5263005/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com