我正在尝试编写一个 MSBuild 脚本,该脚本将对另一个构建进行排队,然后等待该构建完成,然后在排队的构建完成后处理脚本中的进一步步骤。我希望第一个构建继续处于运行状态,直到该构建中的排队构建完成。可以做这样的事情吗?脚本是否必须继续检查构建及其状态,或者排队的构建是否需要在完成第一个构建后发回?
不幸的是,我在谷歌上找不到任何可以帮助我的东西。下面是我用来对构建进行排队的代码。
任何关于如何解决此问题的建议或反馈将不胜感激。
<MSBuild.ExtensionPack.Tfs2010.TeamBuild TaskAction="Queue"
TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
TeamProject="Team_Proj"
BuildDefinitionName="Build_Def"
ContinueOnError="False" />
最佳答案
我能够通过编写 MSBuild 自定义任务来实现这一目标 - 请参阅下面的任务代码
引用以下链接了解此任务的创建和使用
引用链接:- http://blogs.msdn.com/b/msbuild/archive/2006/01/21/515834.aspx
public class QueueBuild : ITask
{
public IBuildEngine BuildEngine
{ get; set; }
public ITaskHost HostObject
{ get; set; }
[Required]
public string tfsServer
{ get; set; }
[Required]
public string teamProject
{ get; set; }
[Required]
public string buildDefinition
{ get; set; }
public bool Execute()
{
// set up support for logging
TaskLoggingHelper loggingHelper = new TaskLoggingHelper(this);
// Log Variables
loggingHelper.LogMessageFromText("Custom Task QueueBuild Starting", MessageImportance.High);
loggingHelper.LogMessageFromText("tfsServer = " + tfsServer , MessageImportance.High);
loggingHelper.LogMessageFromText("teamProject = " + teamProject , MessageImportance.High);
loggingHelper.LogMessageFromText("buildDefinition = " + buildDefinition , MessageImportance.High);
// Get the team foundation server
TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(tfsServer);
// Get the IBuildServer
IBuildServer buildServer = (IBuildServer)tfs.GetService(typeof(IBuildServer));
// Get the build definition for which a build is to be queued
IBuildDefinition buildDef = buildServer.GetBuildDefinition(teamProject, buildDefinition);
// Create variable for queuedBuild and queue the build
var queuedBuild = buildServer.QueueBuild(buildDef);
loggingHelper.LogMessageFromText("Waiting for newly queued build from Team Project : " + teamProject + " : and Build Definition : " + buildDefinition + " : to complete", MessageImportance.High);
loggingHelper.LogMessageFromText("Pinging queuedBuild : " + queuedBuild + " : every 5 seconds to confirm when build is complete", MessageImportance.High);
// Wait for the completion of newly queued build - Will ping build every 5 seconds to confirm completion for a max of 5 hours
queuedBuild.WaitForBuildCompletion(TimeSpan.FromSeconds(5), TimeSpan.FromHours(5));
loggingHelper.LogMessageFromText("Queued Build : " + queuedBuild.Build.BuildNumber + " has now completed", MessageImportance.High);
loggingHelper.LogMessageFromText("Returning to original build", MessageImportance.High);
return true;
}
}
关于c# - 将另一个构建排队,然后等待构建完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26785700/