Skip to content

Instantly share code, notes, and snippets.

@jstangroome
Created March 27, 2011 22:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jstangroome/889708 to your computer and use it in GitHub Desktop.
Save jstangroome/889708 to your computer and use it in GitHub Desktop.
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" -->
<Sequence>
<Sequence.Variables>
<Variable x:TypeArguments="mtbc:IBuildDetail" Name="LastBuildDetail" />
<Variable x:TypeArguments="x:Int32" Name="LastWarningCount" />
<Variable x:TypeArguments="x:Int32" Name="WarningCount" />
</Sequence.Variables>
<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]">
<If.Then>
<Sequence>
<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" />
</Sequence>
</If.Then>
</If>
</Sequence>
@greggbjensen
Copy link

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

@greggbjensen
Copy link

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.

BuildDetail.BuildServer.GetBuild(BuildDetail.BuildDefinition.LastGoodBuildUri)

Copy link

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