是否可以同步排隊構建?TFS 2010 API:隊列同步構建並獲取每個排隊構建的狀態:「在代理上運行(等待構建代理)」
我想是這樣的:
CodeActivity:
[BuildActivity(HostEnvironmentOption.Agent)]
public sealed class QueueNewBuild : CodeActivity<BuildResult>
{
// The Team Project that the build definition belongs to.
[RequiredArgument]
public InArgument<IBuildDetail> BuildDetail { get; set; }
// The build definition to queue
[RequiredArgument]
public InArgument<String> BuildDefinition { get; set; }
protected override BuildResult Execute(CodeActivityContext context)
{
// Obtain the runtime value of the input arguments
var buildDefinitionName = context.GetValue(BuildDefinition);
var buildDetail = context.GetValue(BuildDetail);
// Obtain the Team Project for the current build definition.
var tfsProject = buildDetail.BuildDefinition.TeamProject;
var configurationServerUri = buildDetail.BuildServer.TeamProjectCollection.Uri.ToString();
var server = new TfsTeamProjectCollection(new Uri(configurationServerUri));
server.EnsureAuthenticated();
var buildServer = server.GetService<IBuildServer>();
var buildDefinition = buildServer.GetBuildDefinition(tfsProject, buildDefinitionName);
var queuedBuild = buildServer.QueueBuild(buildDefinition);
var buildStatusWatcher = new BuildStatusWatcher(queuedBuild.Id);
buildStatusWatcher.Connect(buildServer, tfsProject);
do
{
} while (buildStatusWatcher.Status != QueueStatus.Completed && buildStatusWatcher.Status != QueueStatus.Canceled);
buildStatusWatcher.Disconnect();
return new BuildResult
{
WasSuccessfully = buildStatusWatcher.Build.CompilationStatus == BuildPhaseStatus.Succeeded,
BuildDetail = buildStatusWatcher.Build
};
}
}
BuildResult:
public class BuildResult
{
public bool WasSuccessfully { get; set; }
public IBuildDetail BuildDetail { get; set; }
}
BuildStatusWatcher:
public class BuildStatusWatcher
{
private IQueuedBuildsView _queuedBuildsView;
private readonly int _queueBuildId;
private QueueStatus _status;
private IBuildDetail _build;
public BuildStatusWatcher(int queueBuildId)
{
_queueBuildId = queueBuildId;
}
public IBuildDetail Build
{
get { return _build; }
}
public QueueStatus Status
{
get { return _status; }
}
public void Connect(IBuildServer buildServer, string tfsProject)
{
_queuedBuildsView = buildServer.CreateQueuedBuildsView(tfsProject);
_queuedBuildsView.StatusChanged += QueuedBuildsViewStatusChanged;
_queuedBuildsView.Connect(10000, null);
}
public void Disconnect()
{
_queuedBuildsView.Disconnect();
}
private void QueuedBuildsViewStatusChanged(object sender, StatusChangedEventArgs e)
{
if (e.Changed)
{
var queuedBuild = _queuedBuildsView.QueuedBuilds.FirstOrDefault(x => x.Id == _queueBuildId);
if (queuedBuild != null)
{
_status = queuedBuild.Status;
_build = queuedBuild.Build;
}
}
}
}
所以我試圖等待只要構建完成或取消,但這不起作用,因爲子構建的構建代理正在等待整個時間。
我有一個主構建過程(在代理1上運行),它調用13個子構建過程(全部在代理2上運行)。我想等待每個子構建過程,以便在子構建過程失敗時放棄主構建過程。
任何想法?
UPDATE:
服務 'XXX - 劑1' 有一個例外:異常消息: 操作沒有的00:00:30在規定的超時時間內完成。 分配給此操作的時間可能是 較長超時的一部分。 (類型FaultException`1)
異常堆棧跟蹤:在 Microsoft.TeamFoundation.Build.Machine.BuildAgentService.TerminateWorkflow(TerminatingException EX)
的工作流程:
所以,你說所有你的程序要求構建失敗開始?或者你不能訂購多個版本? – pantelif 2012-02-16 11:01:21
它掛在第一個排隊的子版本上。 「Run On Agent(正在等待構建代理)。子構建的構建代理具有狀態:」執行工作流程「。主構建的構建代理狀態爲:」準備就緒「 – Rookian 2012-02-16 11:35:57
我發現代理沒有編譯代理「掛起」零星 – Rookian 2012-02-17 09:10:33