Im using the enum Microsoft.TeamFoundation.Build.Client.BuildStatus for each and it works great for the statuses contained in it.
But is there a blat开发者_如何学Pythonantly obvious way of determining if a build is queued, but not yet in progress? I know the build explorer in visual studio can see this, im having problems getting that data programmatically.
Do i have to check something on the teamproject instead of the IBuildDetail itself? Any tips appreciated.
Unfortunately it doesn't appear that IBuildDetailSpec
queries ever return queued builds. However, you can use the IQueuedBuildSpec
interface to query for queued builds.
For example:
public IEnumerable<IQueuedBuild> getQueuedBuilds(TfsTeamProjectCollection tfsCollection, string teamProject)
{
// Get instance of build server service from TFS
IBuildServer buildServer = tfsCollection.GetService<IBuildServer>();
// Set up query
IQueuedBuildSpec spec = buildServer.CreateBuildQueueSpec(teamProject);
spec.Status = QueueStatus.Queued;
// Execute query
IQueuedBuildQueryResult result = buildServer.QueryQueuedBuilds(spec);
// Array of queued builds will be in the result.QueuedBuilds property
return result.QueuedBuilds;
}
You should be able to see the build status as BuildStatus.NotStarted
once the build actually reaches the queue. There is a time before it reaches the queue that it really doesn't have a status, though.
If you're submitting your build programmatically, you can do:
bool success = queue.WaitForBuildStart(pollingIntervalInMilliseconds, timeOutInMilliseconds);
As long as the agent is listening, this should actually return very quickly. If you have a slow network, this could potentially take a couple seconds for handshaking.
Once it passes the WaitForBuildStart, the status is set to BuildStatus.NotStarted
until it moves to InProgress
and the rest of the way down the line.
@Greg Case First thank you for the code , you gave me the solution that I was searching for. Second , I want to suggest using the same code snippet of yours to receive notifications from TFS for specific Queued build. I already used it to get notified that the build I queued is completed and it even returns exception details for failure case . To do that you need to connect() to the queued build returned from code and then register event , I wanted to add it as a comment but couldn't for long text
IQueuedBuild CurrentBuild = result.QueuedBuilds.First();
CurrentBuild.Connect();
CurrentBuild.PollingCompleted += CurrentBuild_PollingCompleted;
精彩评论