Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A snippet from an extended DefaultTemplate.xaml TFS 2010 Build Process Template for failing the build when the number of compile warnings increases.
<!-- Insert this Sequence as one of the last children of the Sequence with DisplayName="Compile and Test" -->
<Variable x:TypeArguments="mtbc:IBuildDetail" Name="LastBuildDetail" />
<Variable x:TypeArguments="x:Int32" Name="LastWarningCount" />
<Variable x:TypeArguments="x:Int32" Name="WarningCount" />
<Assign x:TypeArguments="mtbc:IBuildDetail" To="[LastBuildDetail]" Value="[BuildDetail.BuildServer.GetBuild(BuildDetail.BuildDefinition.LastBuildUri)]" />
<Assign x:TypeArguments="x:Int32" To="[LastWarningCount]" Value="[Microsoft.TeamFoundation.Build.Client.InformationNodeConverters.GetBuildWarnings(LastBuildDetail).Count]" />
<Assign x:TypeArguments="x:Int32" To="[WarningCount]" Value="[Microsoft.TeamFoundation.Build.Client.InformationNodeConverters.GetBuildWarnings(BuildDetail).Count]" />
<If Condition="[WarningCount &gt; LastWarningCount]">
<mtbwa:WriteBuildError Message="This build has more warnings than the last build. Focus on fixing more build warnings than are introduced." />
<!-- The follow SetBuildProperties line will mark the build as Failed instead of just Partially Successful if the warning count has increased. -->
<mtbwa:SetBuildProperties PropertiesToSet="Status" Status="Failed" />

This comment has been minimized.

Copy link

@greggbjensen greggbjensen commented Jan 9, 2013

Thank you for the code snippet. This is exactly what I was looking for.


This comment has been minimized.

Copy link

@greggbjensen greggbjensen commented Jan 29, 2013

I would recommend one change which is to use the last good build instead of just the last build. Because when a build fails or is cancelled, it will have less warnings, and the next build will have more.



This comment has been minimized.

Copy link

@ghost ghost commented Nov 8, 2013

There are a few things that need to be changed for this to work as expected.

First, this doesn't account for any warnings that appear in the "Other Warnings & Errors" section in the build summary. The "LastWarningCount" is the total number of warnings, and the "WarningCount" is only the number of warnings generated from MSBuild.

Second, since a "good build" is one where both "CompilationStatus" and "TestStatus" are "Succeeded", then one of these values needs to be set to "Failed". Otherwise, the next time you queue a build, it will continue to falsely recognize builds that failed due to warnings as the "LastGoodBuild".

So, I would add the following in addition to using "LastGoodBuild":

<mtbwa:SetBuildProperties PropertiesToSet="CompilationStatus" Status="Failed" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment