Realizing Continuous Integration With Cruise Control.Net (CC.Net)

Realizing Continuous Integration with Cruise Control.Net (CC.Net)
 

Cruise Control

 
Cruise Control is a free and open-source build scheduler implemented using the .Net Framework. It is composed of the following two components:
  1. Build Loop: The build loop is designed to run as a background process, that periodically checks the defined repository for changes in the codebase, builds it, and provides the status as the final output.
  2. Reporting: Cruise Control provides a reporting application to browse the results of the builds and provides a dashboard for the visual representation of the status.
As mentioned in my last article Cruise Control works with many source control systems. (Some of the better known are TFS, SVN, and VSS, and so on.) Input for the build process is any parseable format so it can be integrated with any build tool (MSBuild, Nant, Maven, and so on) that produces a parseable format. In addition to that this is widely used because of its extensive documentation. It also provides the option of a Mailing list.
 
Process of Cruise Control
  1. Developer Checks-in the code
  2. Cruise Controls polls the Version control system (Repository) to see if there are any changes in the codebase
  3. If the changes are there, then Cruise Control triggers the build using the defined build tool, captures the build data, and produces the Build Status Report

CCTray

 
It is a standalone application that enables the developers or any other team member to check the status of the builds on their local machines that can access the CC.Net Server.
 

High-Level Architecture of CC.Net

 
Continuous-Integration-with-Cruise-Control-1.jpg
 

Setup Cruise Control.Net

 
First of all download CC.Net EXE (CruiseControl.NET-1.8.3.0-Setup.exe) from http://sourceforge.net/projects/ccnet/
 
Run that EXE as Administrator. When installing, select all three components.
 
Continuous-Integration-with-Cruise-Control-2.jpg
 
Continuous-Integration-with-Cruise-Control-3.jpg
 
After the installation is complete, you can now access the dashboard by typing in the following URL:
http://localhost:8080/
 
At the physical path of installation you will see that there are three folders that were created named:
  1. webdashboard
  2. Examples
  3. server
In the "server" folder there is a file named "ccnet.config". Open this file to do the configuration for automated builds. We need to add four blocks named:
  1. Project Configuration Block: Information about the project that needs to be built, there can be multiple projects present in this config
  2. SourceControl block: From where the code needs to be checked out for the build
  3. Tasks block: Steps/process of the build
  4. Publishers block: Generate output and produce reports (if needed, dispatch emails also)
For adding these you can either refer to the links above or I am providing you with the sample config below:
  1. <cruisecontrol xmlns:cb="urn:ccnet.config.builder">  
  2.     <!-- This is your CruiseControl.NET Server Configuration file. Add your projects below! -->  
  3.     <project name="Sample Application">  
  4.         <webURL>http://localhost:8080/ccnet/server/local/project/SampleApplication/ViewLatestBuildReport.aspx</webURL>  
  5.         <!--set the sourcecontrol type to subversion and point to the subversion exe-->  
  6.         <sourcecontrol type="svn">  
  7.             <executable>C:\Program Files\TortoiseSVN\bin\svn.exe</executable>  
  8.             <workingDirectory>  
  9.         <PATHOFYOURAPPLICATION>\SampleApplication  
  10.       </workingDirectory>  
  11.             <trunkUrl>  
  12.         <REPOSITORYPATH/URL>/SampleApplication  
  13.       </trunkUrl>  
  14.             <autoGetSource>true</autoGetSource>  
  15.             <username>XXXX</username>  
  16.             <password>XXXX</password>           
  17.     </sourcecontrol>  
  18.         <triggers>  
  19.             <intervalTrigger name="Cruise Control Continuous Integration" seconds="60" buildCondition="IfModificationExists" initialSeconds="30" />           
  20.     </triggers>  
  21.         <tasks>  
  22.             <!-- Configure MSBuild to compile the updated files -->c:\  
  23.             <msbuild>  
  24.                 <executable>c:\windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe</executable>  
  25.                 <workingDirectory>  
  26.           <PATHOFYOURAPPLICATION>\SampleApplication\  
  27.         </workingDirectory>  
  28.                 <projectFile>SampleApplication.sln</projectFile>  
  29.                 <buildArgs>/noconsolelogger /p:Configuration=Debug /nologo</buildArgs>  
  30.                 <targets></targets>  
  31.                 <timeout>60</timeout>  
  32.                 <logger>C:\Program Files (x86)\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger>               
  33.       </msbuild>  
  34.             <exec>  
  35.                 <executable>del.bat</executable>  
  36.                 <buildArgs></buildArgs>  
  37.                 <buildTimeoutSeconds>30</buildTimeoutSeconds>               
  38.       </exec>         
  39.             <exec>  
  40.                 <!--Call mstest to run the tests contained in the TestProject -->  
  41.                 <executable>C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe</executable>  
  42.                 <baseDirectory>  
  43.           <PATHOFYOURAPPLICATION>\\SampleApplication\Web\bin\debug  
  44.         </baseDirectory>  
  45.                 <!--testcontainer: points to the DLL that contains the tests -->  
  46.                 <!--runconfig: points to solutions testrunconfig that is created by vs.net, list what test to run -->  
  47.                 <!--resultsfile: normally the test run log is written to the uniquely named testresults directory  -->  
  48.                 <!--                   this option causes a fixed name copy of the file to be written as well -->  
  49.                 <buildArgs>                              
  50.         </buildArgs>  
  51.                 <buildTimeoutSeconds>60</buildTimeoutSeconds>               
  52.       </exec>           
  53.     </tasks>  
  54.         <!--Publishers will be done after the build has completed-->  
  55.         <publishers>  
  56.             <buildpublisher>  
  57.                 <sourceDir>  
  58.           <PATHOFYOURAPPLICATION>\\SampleApplication\Web\  
  59.         </sourceDir>  
  60.                 <publishDir>  
  61.           <PATHOFYOURAPPLICATION>\\Sample Application 9091  
  62.         </publishDir>  
  63.                 <useLabelSubDirectory>false</useLabelSubDirectory>  
  64.                 <alwaysPublish>false</alwaysPublish>  
  65.                
  66.       </buildpublisher>  
  67.             <merge>  
  68.                 <files>  
  69.                     <file action="Merge" deleteAfterMerge="true">msbuild-results.xml</file>  
  70.                     <file action="Merge" deleteAfterMerge="true">  
  71.             <PATHOFYOURAPPLICATION>\\SampleApplication\Web\bin\Debug\testResults.trx  
  72.           </file>  
  73.                    
  74.         </files>  
  75.                
  76.       </merge>  
  77.             <xmllogger/>  
  78.             <email from="[email protected]" mailhost="smtp.XXXX.com" mailport="25" useSSL="FALSE" mailhostUsername=[email protected]" includeDetails="TRUE" mailhostPassword="XXXX" >  
  79.                 <users>  
  80.                     <user name="Abhishek" group="buildmaster" address=[email protected]" />  
  81.                     <user name="Devs" group="developers" address=[email protected]" />                   
  82.                </users>  
  83.                 <groups>  
  84.                 <group name="developers">  
  85.                 <notifications>  
  86.                 <notificationType>Failed</notificationType>                           
  87.             </notifications>                       
  88.           </group>  
  89.                     <group name="buildmaster">  
  90.                     <notifications>  
  91.                     <notificationType>Always</notificationType>                           
  92.             </notifications>                       
  93.           </group>                   
  94.         </groups>               
  95.       </email>           
  96.     </publishers>  
  97.         <modificationDelaySeconds>0</modificationDelaySeconds>       
  98.   </project>  
  99. </cruisecontrol> 
Once we are done with the configurations we need to start the CruiseControl.Net Server. For starting the server open Services.msc ->CruiseControl.Net Server. Start this service.
 
Continuous-Integration-with-Cruise-Control-4.jpg
 
As soon as you are done with that you are ready with your entire configuration to produce automated builds. Access the URL: http://localhost:8080/ViewFarmReport.aspx  and you will see the project that you configured on this dashboard.
 
Continuous-Integration-with-Cruise-Control-5.jpg
 
From here you can force a build and can also check the status of various builds along with the exception details or the error details if any.
 
As I mentioned earlier you can also download CCTray from this page by clicking on the link "Download CCTray". It will help one to see when the error occurred and by looking into it one is immediately notified of the error in the check-in and can resolve it on the fly.