TFS Alert of successful build after failed build
Is there away to get an email of a successful build after a failed build in TFS?
I can get emails when the build fails (which I do). And I can get emails when the build succeeds.
But what I need 开发者_运维百科is to know that the build is no longer failing. If I get an email that the build failed, I don't want to check in until it is working again. It would be nice to get that info by email.
I don't believe this will be possible using the Alerts Explorer. But you could create a custom web service that subscribed to the Build Notifications then implement this logic yourself.
See this article for details on subscribing to TFS events with your own web service: http://blog.hinshelwood.com/team-foundation-server-2010-event-handling-with-subscribers/
I currently have the TFS setup email alerts for failure and success builds. I think success build emails are just a noise and I want to get them only if the last build was a failure. My idea was to cancel the TFS alert email for any success build, but enable it for success after failure builds I have successfully hooked up the code to find out if the last build failed and the current build succeeded using a TFS plugin.
public EventNotificationStatus ProcessEvent(TeamFoundationRequestContext requestContext, NotificationType notificationType,
object notificationEventArgs, out int statusCode, out string statusMessage, out ExceptionPropertyCollection properties)
{
statusCode = 0;
properties = null;
statusMessage = string.Empty;
var objWriter = new System.IO.StreamWriter(@"C:\tfsTests\builds.txt", true);
objWriter.WriteLine(DateTime.Now + "-----------------------------------------------");
objWriter.WriteLine(DateTime.Now + notificationType.ToString());
objWriter.WriteLine(DateTime.Now + notificationEventArgs.ToString());
if ((notificationType == NotificationType.Notification) && (notificationEventArgs is BuildCompletionNotificationEvent))
{
var buildNotificationEventArgs = notificationEventArgs as BuildCompletionNotificationEvent;
objWriter.WriteLine(DateTime.Now + buildNotificationEventArgs.Build.ToString());
objWriter.WriteLine(DateTime.Now + buildNotificationEventArgs.Build.Definition.BuildControllerUri.ToString());
objWriter.WriteLine(DateTime.Now + buildNotificationEventArgs.Build.Definition.LastGoodBuildUri);
objWriter.WriteLine(DateTime.Now + buildNotificationEventArgs.Build.Definition.LastBuildUri);
var locationService = requestContext.GetService<TeamFoundationLocationService>();
var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(
new Uri(locationService.GetServerAccessMapping(requestContext).AccessPoint + "/" + requestContext.ServiceHost.Name));
var buildServer = (IBuildServer)tfs.GetService(typeof(IBuildServer));
var spec = buildServer.CreateBuildDetailSpec(buildNotificationEventArgs.Build.TeamProject, buildNotificationEventArgs.Build.Definition.Name);
spec.MaxBuildsPerDefinition = 2;
spec.QueryOrder = Microsoft.TeamFoundation.Build.Client.BuildQueryOrder.FinishTimeDescending;
var builds = buildServer.QueryBuilds(spec);
if (builds.Builds.Count() == 2)
{
if (builds.Builds[0].Status == BuildStatus.Succeeded && builds.Builds[1].Status != BuildStatus.Succeeded && builds.Builds[0].FinishTime > builds.Builds[1].FinishTime)
objWriter.WriteLine(string.Format("{0}", "Send Email"));
}
}
objWriter.Close();
return EventNotificationStatus.ActionPermitted;
}
I just don't know how to send the same TFS build email. Do you know how to do this ?
精彩评论