For the list of all the posts in this series please read this one
Context
We can see all the build results of a team project easily inside Team Explorer or with the Web Access but there is no way to see the build results of all team projects at the same time. Using a simple query and a few Linq operators we can get a useful little report in LinqPad.
Required references
Microsoft.TeamFoundation.Build.Client.dll
Microsoft.TeamFoundation.Client.dll
Microsoft.TeamFoundation.Framework.Client.dll
Query (C# Statements)
var tfs = TfsTeamProjectCollectionFactory .GetTeamProjectCollection(new Uri("http://localhost:8088/tfs")); tfs.EnsureAuthenticated(); var buildServer = tfs.GetService<IBuildServer>(); var spec = buildServer.CreateBuildDetailSpec("*"); spec.MinFinishTime = DateTime.Now.Subtract(TimeSpan.FromDays(7)); spec.MaxFinishTime = DateTime.Now; spec.QueryDeletedOption = QueryDeletedOption.IncludeDeleted; var builds = buildServer.QueryBuilds(spec).Builds; var total = builds.Sum(b => b.FinishTime.Subtract(b.StartTime).TotalMinutes); builds.Select(x => new { Project = x.TeamProject, Definition = x.BuildDefinition.Name, Version = x.SourceGetVersion, Developer = x.RequestedFor, Type = x.Reason, Start = x.StartTime, Duration = x.FinishTime.Subtract(x.StartTime), Build = x.CompilationStatus, Tests = x.TestStatus, Result = x.Status, StyleCopViolations = InformationNodeConverters.GetBuildWarnings(x) .Count(inc => inc.Message.StartsWith("SA")), FxCopViolations = InformationNodeConverters.GetBuildWarnings(x) .Count(inc => inc.Message.StartsWith("CA")), Warnings = InformationNodeConverters.GetBuildWarnings(x) .Select(inc => inc.Message) .Where(m => !m.StartsWith("SA") && !m.StartsWith("CA")), Errors = InformationNodeConverters.GetBuildErrors(x) .Select(inc => inc.Message) }) .OrderByDescending(b => b.Start) .Dump("All builds of the week. Total build duration: " + total);
Result
You will get a list of the build results of all the team projects for the last week. The total build time is at the top of list. Each build result include the build errors, warnings and the number of StyleCop and FxCop violations found (if you have included those static analysis tools in your project template). Also, on line 9 you can change the query to get build results over a longer period of time.
All builds of the week. Total build duration: 20.666666666666667 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
2 comments:
Can we get list of Build Definitions used per project?
Any idea?
You could call buildServer.QueryBuildDefinitions("*") and then get the Name and TeamProject properties
Post a Comment