Posted by Sébastien Lachance with Comments (0)
(Index of the whole series)
Before we go on, you need to now what is "Continuous Integration". This is a long topic and you should probably read Martin Fowler's article on Continuous Integration.
Now that we have determined the structure of the project and put the source in the repository, we need to set up the continuous integration server. The tool we will use for that is CruiseControl.NET. The guys behind it have really done a great job. We need first to define "what we want".
We also want to "fail fast". This means that at any step, if something is wrong, we won't go further and report it.
So here is the step by step approach :
Download CruiseControl.NET here. I'm using the version 1.3. Then double-click on the executable and follow each step. Normally, I'm leaving everything checked except the help files and examples.
You will be asked if you want to use CC.NET server as a Windows Service. Basically, if you want CC.NET to always run (and in my opinion, it should), my advice is to run it as a service. But some scenario may require that you need to run it only once in while. In that case you only need to execute ccnet.exe to start the server. Next, it ask you if you want to create a virtual directory in IIS for the Web Dashboard. I'm leaving it checked as I want to use CC.NET as a service.
Find your ccnet.config (in your ccnetinstallationfolder\server). Every step you want to be executed will be defined here. This require some basic knowledge in xml.
<!--<ccnetconfig><configurationVersion>1.3</configurationVersion></ccnetconfig>-->
<cruisecontrol>
<project name="LogItAll">
</project>
</cruisecontrol>
I'm usually starting with an empty configuration file. The <cruisecontrol> tag is the root and you have one <project> tag per project.
<workingDirectory>c:\dev\logitall</workingDirectory>
<artifactDirectory>c:\dev\logitall\artifact</artifactDirectory>
<category>Personal application</category>
<modificationDelaySeconds>10</modificationDelaySeconds>
<triggers>
<intervalTrigger name="continuous" seconds="30"/>
</triggers>
<labeller type="defaultlabeller">
<prefix>0.0.</prefix>
</labeller>
The <workingDirectory> will serve as the root for all our operations. Instead of specifying the full path, we will use the relative path. Example : \tools\nant\nant.exe instead of C:\dev\LogItAll\tools\nant\nant.exe.
The <artifactDirectory> is where every logs (builds, unit tests) is stored. This tag is not needed.
The <category> is simply in which category you want the project to be. This tag is also not needed.
The <modificationDelaySeconds> is the interval of time in which no modification must be done to the source to continue executing all remaining tasks.
We then have the triggers bloc. This block contains all the reasons that we want to perform a build. I recommend using the documentation of CC.NET to learn more. The <intervalTrigger> is, as the name imply, a trigger that will launch the build process every 30 seconds if any modifications is done to the source.
Finally we have the <labeller> which will give a label to the project. There is a lot of different labelers to use. In my case, I'm going with the default and starting the build number at 0.0.*.
The sourcecontrol tag is need to know if the source have changed. This will also get the latest version of the project.
...
<sourcecontrol type="svn">
<trunkUrl>svn://localhost/repos/LogItAll</trunkUrl>
</sourcecontrol>
I can't go on all the details because each source control has it's own set of properties and features.
A lot of source control providers are supported (SourceSafe,CVS, etc..).
First, we need a <tasks> section. This section should contains all action you want to happen in order. Several tasks are available.
A build file will help tremendously. Since we already have the build process in our own file for development, why shouldn't we use it to build the application on the CI server. Instead of using an MSBuild task and modifying two files each time we change something in our build process, we should use it. You can use the nant task to run our build file.
<tasks>
<nant>
<executable>tools\nant\nant.exe</executable>
<buildFile>logitall.build</buildFile>
<targetList>
<target>test</target>
</targetList>
</nant>
</tasks>
Every log files you want to see in the Web Dashboard need to be merged. To do that you need to add the File Merge Task of the publisher task.
<publishers>
<merge>
<files>
<file>Logs\*.xml</file>
</files>
</merge>
<xmllogger/>
</publishers>
This will embed the content of all the xml files in the logs folder in an xml file that the Web Dashboard will use to render it's content. It's really important that you add the <xmllogger>. It is required for the Web Dashboard to function properly.
If you are like me and you are using MbUnit as a test tool, you will need to perform some additional step to integrate your results files into the Web Dashboard. The solution is described in the Andrew Stopford's Weblog. If you don't see the report after that, verify that MbUnit genarate an xml file instead of an html file.
The Web Dashboard is the easiest way to see every test results, builds logs, coverage statistics, etc...
You can access it via the http://nameofyourserver/ccnet.
CCTray is a little application that helps you monitor your build. Simply access you Web Dashboard, and it the left menu, there is an option to download CCTray.
Then you need to add the projects you want to monitor. You do that first by entering the name of the server and then selecting the projects you want. I'm usually using the "Connect directly using .NET remoting.
Keep in mind that it is a basic tutorial and I intend to develop a little more in the following months. In the meanwhile, I will appreciate any comments, suggestion or ideas.
(Put me in your feed reader ! :P)