Setting up Cruise Control Ccnet Autobuild For Every Chekin

To keep your code clean and in a compiled form we need to keep track that no erroneous file gets checked-in to your code repository. The best way to perform this is to use an autobulid process when a new checkin in repository happens. Recently I tried to perform the same and so came to write about the quick steps
First of all, you need tools that will automatically keep your code clean and without an erroneous file by performing an autobulid process when a new checkin to the repository is done. I recommend the CruiseControl .Net tool for this. It's free and open source.
If you're using an SVN subversion control then it requires an svn client to get the latest source code and checkin detection.
I prefer Collabnet subversion client.
Download Cruise Control and Install it with easy next –> next –> finish steps. It'll ask you to create an IIS website so make sure you've IIS installed. The website will be your dashboard to check your build status and reports.
Once you are done with the installation, go to the directory where you installed the tool. The default path for this is:
For (64 bit)
C:\Program Files (x86)\CruiseControl.NET
For (x86)
C:\Program Files\CruiseControl.NET
Now go to the "server" subdirectory on the above location and you'll find the ccnet.config file. Open this file in your favourite XML editor (mine is NotePad++). In case you're using Notepad++ don't forget to select the language from the menu to choose XML.
Edit your ccnet.config file with your project, svn and other details like in the following sample:
  1. <cruisecontrol xmlns:cb="urn:ccnet.config.builder">  
  2.   <project name="Code library - 1.0 - Local">  
  3.     <!--Mention you name of project directory location here -->  
  4.     <workingDirectory>D:\Projects\CodeLibrary\</workingDirectory>  
  5.     <!--for reports and logs-->  
  6.     <artifactDirectory>D:\Artifacts</artifactDirectory>  
  7.     <!--Url for the web dashboard of cruise control-->  
  8.     <webURL>http://localhost/ccnet</webURL>  
  10.     <triggers>  
  11.       <!-- Give trigger sepcification when the build should kick off -->  
  12.       <intervalTrigger name="continuous" seconds="300" buildCondition="IfModificationExists" />  
  13.     </triggers>  
  14.     <!-- Incremental label for your each build-->  
  15.     <labeller type="defaultlabeller">  
  16.       <prefix>1.0.</prefix>  
  17.       <incrementOnFailure>false</incrementOnFailure>  
  18.       <labelFormat>0000</labelFormat>  
  19.     </labeller>  
  20.     <!-- configure your svn details-->  
  21.     <sourcecontrol type="svn">  
  22.       <trunkUrl>http://amit.subverions.url/svn/CodeLibrary</trunkUrl>  
  23.       <workingDirectory>D:\Projects\CodeLibrary\</workingDirectory>  
  24.       <executable>C:\Program Files (x86)\CollabNet\Subversion Server\svn.exe</executable>  
  25.       <username>svn_user</username>  
  26.       <password>svn_pwd</password>  
  27.       <autoGetSource>true</autoGetSource>  
  28.       <tagOnSuccess>false</tagOnSuccess>  
  29.       <tagBaseUrl></tagBaseUrl>  
  30.     </sourcecontrol>  
  31.     <!-- setting up tasks for build your project-->  
  32.     <tasks>  
  33.       <msbuild>  
  34.         <executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe</executable>  
  35.         <workingDirectory>D:\Projects\CodeLibrary\</workingDirectory>  
  36.         <projectFile>Amit.Tests.Tools.CodeLibrary.sln</projectFile>  
  37.  <buildArgs>/noconsolelogger /p:Configuration=Release /p:Platform="Any CPU" /v:diag </buildArgs>  
  38.         <targets>Build</targets>  
  39.         <timeout>600</timeout>  
  40.         <!-- Make sure to change the path based on your platform architecture (x86) or 64-->  
  41.         <logger>C:\Program Files (x86)\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger>  
  42.       </msbuild>  
  43.     </tasks>  
  44.     <!-- This is something you would only required if you want to merge multiple generated reports into one for e.g. your unit test reports-->  
  45.     <publishers>  
  46.       <merge>  
  47.         <files>  
  48.           <file>K:\Artifacts\msbuild-results.xml</file>  
  49.         </files>  
  50.       </merge>  
  51.       <xmllogger />  
  52.       <statistics/>  
  53.     </publishers>  
  54.   </project>  
  55. </cruisecontrol> 
When you are done editing save it and close it.
Now open the file.
C:\Program Files (x86)\CruiseControl.NET\webdashboard\dashboard.config
  1. <buildReportBuildPlugin>  
  2.   <xslFileNames>  
  3.     <xslFile>xsl\header.xsl</xslFile>  
  4.     <xslFile>xsl\modifications.xsl</xslFile>  
  5.     <xslFile>xsl\compile.xsl</xslFile>  
  6.     <xslFile>xsl\compile-msbuild.xsl</xslFile>  
  7.   </xslFileNames>  
  8. </buildReportBuildPlugin>  
  9. <buildLogBuildPlugin /> 
Add the above mentioned XSL files. These templates are already installed with your CruiseControl tool.
Now you're almost done with configuration.
Go to services and start CruiseControlServer
Once the service started it'll start watching your project for the latest checkins. If the service is not starting then there's a problem with your configuration XML. Double-check it.
Now open the url http://localhost/ccnet make sure it's showing you cruise control dashboard and your project name is visible there.
And you're done. Now download the CCTray from the above dashboard and add a project as HTTP url(i.e.http://localhost/ccnet) from the add server setting. If it's connected it'll show you the project and its state with color-coding 'Green' (Means everything is ok).
Now checkin a code file in your project and watch it building from CCTray.
  1. Web dashboard is not showing my project
    Make sure you've placed your ccnet.config in the server directory and it's updated with your project info. and that the Cruise control services are running.
  2. error – Your svn copy is too old to work with the subversion svn client.
    Try to download an earlier version of collabnet subversion svn client and restart the service again. Further if it can give an error – Your svn subversion is too old to work with your svn repository. Now you can install your previous collabnet subversion client and it should work.
  3. MSbuild task failed -
Make sure your arguments and project directory information are correctly specified in the ccnet.config file. Try to run the MSBuild command argument in vs command prompt if it works fine there then it will definitely work here.