Monday, February 9, 2009

Continuous Integration - Force a build to fail when unit tests fail and create work item

I had to setup continuous build on my TFS2008 machine which had to run a specific set of tests before it created a build (whenever anyone check’s in any code). I was pretty much successful doing that. The process was running smooth but whenever a test used to fail the build used to “Partially Fail” and also it didn’t create a “Bug” and assign it to the person who broke the build. A Bug was assigned to the person who broke the build only when the build used to “Fail”.
I did some RnD in this and figured out a way to force a build to fail whenever a test failed. I wrote the below line in the TFSBuild.proj file

< treattestfailureasbuildfailure > true < /treattestfailureasbuildfailure >
Adding this I thought, as I am forcing the test fail to be treated as a Build Failure, TFS will take care of raising a work item or Bug to the person but it didn’t.
Then I wrote a Target in the same file to create a work item on Test failure.

<UsingTask TaskName="Microsoft.TeamFounadtion.Build.Tasks.CreateNewWorkItem"

AssemblyFile="$(TeamBuildRefPath)\Microsoft.TeamFoundation.Build.Tasks.VersionControl.dll" />

<Target Name="AfterTest">

<!-- Refresh the build properties. -->

<GetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)"


Condition=" '$(IsDesktopBuild)' != 'true' ">

<Output TaskParameter="TestSuccess" PropertyName="TestSuccess" />


<!-- Set CompilationStatus to Failed if TestSuccess is false. -->

<SetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)"



Condition=" '$(IsDesktopBuild)' != 'true' and '$(TestSuccess)' != 'true' ">





Description="The CreateNewWorkItem task created this bug."



Title="Unit Test Failure in $(BuildNumber)"



Condition=" '$(IsDesktopBuild)' != 'true' and '$(TestSuccess)' != 'true' ">



No comments: