index-1-1.jpg
  • Aurora Solutions

Getting Started With CruiseControl.NET

This is the second article of the series. In the last article we had discussed about the Continuous Integration (CI) and its advantages, now lets move toward setting the CI using some tools. There are many tools available for configuring CI. CI is not possible without any source control system. There are many CI servers for .net environment but we will undergo with CruiseControl.net(CCNet).


CruiseControl.net:

Its an open source system and is easily available. You can download the latest version of ccnet from here.


Installing ccnet:

Run the setup installation file you will see an installation wizard click next then accept license agreement and click next you will see the following screen


If you have installed IIS on the same machine then you can install web dashboard it is strongly recommended that you should install web dashboard. As in CI most important part is feedback that is you always wanted to know that what happened with build? Was it succeeded or failed? What happened with the test cases? How many of them were succeeded and and how many were failed?. You can get all this information in a Web dashboard.


You can configure to run ccnet as your window service in this screen, if you have installed IIS on your machine by second option it will configure everything you need. While installing Web Dashboard if you get a message to select ASP.net version choose at least 2.0.


Configuring ccnet:

After the installation completes then only thing you need is to configure ccnet and all things will work. To access configuration file go to the installation directory or by default %Program Files%CruiseControl.NETserverccnet.config. You can open ccnet.config file in notepad and edit it. Its an xml based configuration file. By default it looks like the following

<cruisecontrol xmlns:cb="urn:ccnet.config.builder">
<!-- This is your CruiseControl.NET Server Configuration file. Add your projects below! -->
<project name="MyFirstProject"
description="demoproject showing a small config">
<triggers>
<!-- check the source control every X time for changes,and run the tasks if changes are found -->
<intervalTrigger
name="continuous"
seconds="30"
buildCondition="IfModificationExists"
initialSeconds="5"/>
</triggers>

<sourcecontrol type="nullSourceControl" alwaysModified="true"></sourcecontrol>
<tasks>
<exec>
<!-- if you want the task to fail, ping an unknown server -->
<executable>ping.exe</executable>
<buildArgs>localhost</buildArgs>
<buildTimeoutSeconds>15</buildTimeoutSeconds>
<description>Pinging a server</description>
</exec>
</tasks>
<publishers>
<xmllogger />
<artifactcleanup cleanUpMethod="KeepLastXBuilds" cleanUpValue="50" />
</publishers>
</project>
</cruisecontrol>

Its the default configuration we have to change it according to our scenario. We will use some trading application(.net code) as our example. Firstly you need to have the basic things in configuration file. Lets discuss one by one and their configuration also.


Project Tag:

ccnet can have multiple projects running at the same time, but we will use only project. We will do step by step configuration.

<cruisecontrol>
 <project name="MarketDataSimulator">
  <workingDirectory>D:Reposcruisecontrol</workingDirectory>
  <artifactDirectory>C:CIArtifacts.Framework</artifactDirectory>
 </project>
</cruisecontrol>

In this we have configured our project name you can change it as you desire. The working directory is set to where the application code is placed. The artifacts directory is for ccnet build logs.

Next step is you need to add trigger.


Triggers

Triggers are important in your CI project that is when your project should build. You can configure it weekly, daily, monthly, or many times per day. We will configure it on daily basis if the modifications occurs in code.

<cruisecontrol>
 <project name="MarketDataSimulator">
  <workingDirectory>D:Reposcruisecontrol</workingDirectory>
  <artifactDirectory>c:CIArtifacts.Framework</artifactDirectory>
  <triggers>
   <scheduleTrigger time="00:00:00" buildCondition="IfModificationExists" name="DailyBuild" />
  </triggers>
</project>
</cruisecontrol>

In the triggers element we have the time of build and also provided buildCondition, i have set it to IfModificationsExisits, which means that if there is a change in the source code then we have to run the build on the time provided. The question is how it knows that the change has occurred in code. It is described in the next section.


SourceControl Tag:

This code section is responsible for getting the code from repository. The repository tells us the code has changed or not if its changed it will pull the latest code. We will use git to get the code here are the settings for it.

<sourcecontrol type="git">
 <workingDirectory>D:Reposcruisecontrol</workingDirectory>
 <executable>C:Program Files (x86)Gitcmdgit.exe</executable>
 <timeout>60000</timeout>
 <autoGetSource>true</autoGetSource>
 <fetchSubmodules>true</fetchSubmodules>
 <repository>https://github.com/aurorablogs/cruisecontrol.git</repository>
 <branch>master</branch>
 <tagOnSuccess>false</tagOnSuccess>
 <commitBuildModifications>false</commitBuildModifications>
</sourcecontrol>

There are many properties in source control tag you can use them to configure it according to your scenario.


Publishser:

Publishers are important in CCNet because they provide feedback mechanism, although you can get feedback from the web dashboard but if you have more project members, stakeholders or team leads, they will not come to web to see what is going on. The publisher sends email to the members after the project build with the result of build. So they will get email and will be updated about the status instead of visiting the web dashboard on specific time as no one remembers that he has to visit web to check status. So this automated publisher will keep them informed.

Here is how you can configure the email publisher i have configured it for gmail server.

<publishers>
 <xmllogger />
 <email mailport="587" includeDetails="TRUE" mailhostUsername="username@gmail.com" mailhostPassword="password" useSSL="True">
  <from>aurorablogs1@gmail.com</from>
  <mailhost>smtp.gmail.com</mailhost>
  <users>
   <user name="user1" group="buildmaster" address="user1@mail.com" />
   <user name="user2" group="buildmaster" address="user2@mail.com" />
   <user name="user3" group="buildmaster" address="user3@mail.com" />
   <user name="user4" group="buildmaster" address="user4@mail.com" />
   <user name="user5" group="buildmaster" address="user5@mail.com" />
  </users>

  <groups>
   <group name="buildmaster">
    <notifications>
     <notificationType>Always</notificationType>
    </notifications>
   </group>
  </groups>
  <subjectSettings>
   <subject buildResult="StillBroken" value="Build is still broken for {CCNetProject}" />
  </subjectSettings>

  <xslFiles>
   <file>xslheader.xsl</file>
   <file>xslcompile.xsl</file>
   <file>xslunittests.xsl</file>
   <file>xslmodifications.xsl</file>
   <file>xslfit.xsl</file>
   <file>xslcompile-msbuild.xsl</file>
   <file>xslNCoverSummary.xsl</file>
  </xslFiles>

  </email>

</publishers>

There are many things you need to configure for an email publisher, first you need the email server settings which varies from server to server, secondly you can make groups. Groups can be used to send a build failed results to specific group and build success to specific group and Always group receives all types of results. The next is xsl files, these are used to include the results of build in email e.g compile-msbuild will include errors in the .net project occurred during compiling the code. Remaining xsl files will be explained in next articles. Make sure you add xmlloger before email publisher it will help email publisher in generating results, if you dont add it or add it after email publisher you will see no results in the mail or even in xml logs.


Tasks Tag:

Its the main tag of ccnet where we include the tasks we need to perform such as compiling .net code or any other thing will be included in this. It has many extensions and usages. We will discuss major extensions in the next articles.

You can view the full project and its ccnet configuration file here. You can place the ccnet config file in the installation directory of ccnet and than run the ccnet it will get the code it self from the repository.


Previous articles link:

1. Introduction to Continuous Integration

Download Project & Config File

Recent Posts

See All

Automating WIX Installer using CCNET

This is the last article of the series Continuous Integration in .NET using Cruise Control.net. In the last article we had discussed that how we can use NUnit with ccnet to run our test cases. In this

Using NUnit with CCNet

This is the fifth article of the series of Continuous Integration in .net using Cruise Control .net. In the last article we had covered the usage of NAnt with ccnet, in this article we move ahead and

Using NAnt with CCNet

This is the fourth article of the series. In the last article we had seen the usage of MSBuild. In this article we will look at the NAnt. NAnt is free and open source software for automating the build