CruiseControl.Net – Installing and configuring with CVS, MSBuild and MSTest

Introduction

CruiseControl.NET is an Automated Continuous Integration server, implemented using the Microsoft .NET Framework. It can be downloaded from: http://goo.gl/yRXo6

CruiseControl.NET (CCnet) has three main components. The core is the Server, which automates the integration process. The Web Dashboard, which is a .Net web app which shows status and a detailed view of the projects. The third component is a system tray app which shows at a glance the state of the projects.

Prerequisites

These should all be installed prior to CCNET:

  • IIS
  • .NET Framework
  • Visual Studio

Installation

CCNet comes with an installer, so installation is simple. Run setup.exe, and click next a few times. CCNet is installed into \Program Files (x86)\CruiseControl.NET\.

Note: At this point, I would give access to the NETWORK SERVICE, and possibly Machine\Users to the \Program Files (x86)\CruiseControl.NET\WebDashboard\packages directory and C:\Program Files (x86)\CruiseControl.NET\server directory. Otherwise, you may have trouble with updating config files, and the builds themselves updating some project files.

Configuration

I am going to go through my configuration which uses CVS, MSBuild and MSTest.

Create the project

Edit the CCNET.config file found in into \Program Files (x86)\CruiseControl.NET\.

<cruisecontrol xmlns:cb=”urn:ccnet.config.builder”>
<!– This is your CruiseControl.NET Server Configuration file. Add your projects below! –>
<project name=”SilverCodeExchange”>
</project>
</cruisecontrol>

Add SVN

Next, we are going to add the configuration for CVS. This goes inside <project>…</project>. We point the executable to the SlickSVN version of svn.exe to do the actual Subversion work.

We assign the trunk URL to your CVS repository. Username and password are for your CVS repository. The working directory specifies local workspace.

<sourcecontrol type=”svn”>
<executable>C:\Program Files\SlikSvn\bin\svn.exe</executable>
<trunkUrl>https://pl3.projectlocker.com/CompanyName/Project/svn</trunkUrl>
<workingDirectory>c:\working\build\SilverCodeExchange</workingDirectory>
<username>username</username>
<password>password</password>
</sourcecontrol>

Trigger the Build

Now, we add a trigger to tell it when to do the build.

<triggers>
<intervalTrigger name=”continuous” seconds=”60″ buildCondition=”IfModificationExists” initialSeconds=”60″ />
</triggers>

This specifies that we want the build to run every 60 seconds, after an initial 60 seconds, but only if there have been code changes.

Adding MSTest

Next, we will add the first of the tasks, MSBuild, this is going to build the debug configuration of the solution.

<tasks>
<msbuild>
<executable>C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe</executable>
<workingDirectory>c:\working\build\SilverCodeExchange</workingDirectory>
<projectFile>SilverCodeExchange.sln</projectFile>
<buildArgs>/p:Configuration=Debug</buildArgs>
<targets>Build</targets>
<timeout>900</timeout>
<logger>
C:\Program Files x86)\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll
</logger>
</msbuild>
</tasks>

The next stage is to add the MSTest task to run our unit tests. This comes in two parts, the first is to create a batch file to delete the existing test results file, because MSTest will not overwrite it, and just stops.

Create a file called DeleteTestResultsFile.bat, and enter this code. Remember to add it in to your source control.

del testresults.trx

Then we need to set up a new task to call this batch file:

<exec>
<executable>
c:\working\build\SilverCodeExchange\SilverCodeExchangeTest\deleteTestResultsFile.bat
</executable>
<baseDirectory>c:\working\build\SilverCodeExchange\</baseDirectory>
<buildArgs></buildArgs>
<buildTimeoutSeconds>30</buildTimeoutSeconds>
</exec>

And now the call to MSTest:

<exec>
<executable>C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe</executable>
<baseDirectory>c:\working\build\SilverCodeExchange</baseDirectory>
<buildArgs>
/testcontainer:SilverCodeExchangeTest\bin\debug\silvercodeExchangeTest.dll
/resultsfile:c:\working\build\SilverCodeExchange\testResults.trx
/runconfig:TraceAndTestImpact.TestSettings
</buildArgs>
<buildTimeoutSeconds>30</buildTimeoutSeconds>
</exec>

Now, it’s with MSTest that I had the most issues. When MSTest runs it creates a new test directory in the format \<username>\<out>\ and copies all the test project executables and dlls. My main issue was that certain files were not being copied into the directory. This is solved by telling Visual Studio that the need to be deployed. Here is how:

  1. In Solution Explorer, right-click Solution Items, point to Add, and then click New Item. The Add New Item dialog box appears.
  2. In the Installed Templates pane, click Test Settings.
  3. (Optional) In the Name box, change the name of the test settings file.
  4. Click Add.
  5. Click on Deployment.
  6. Click the tick box to enable deployment.
  7. Click on add file and add any files which need to be available for the tests to run. (Figure 1)

clip_image002

Figure 1 – Adding Files to test deployment

Next we need ensure that the test results are merged into the build results. So we add a new section:

<publishers>
<merge>
<files>
<file>c:\working\build\SilverCodeExchange\testResults.trx</file>
</files>
</merge>
<!– the reference to xmllogger needs to be here, or strange errors occur.–>
<xmllogger />
</publishers>

Configuring the Web Desktop to show the Test results

We need to edit the dashboard.config file in C:\Program Files (x86)\CruiseControl.NET\webdashboard, update the buildPlugins section:

<buildPlugins>
<buildReportBuildPlugin>
<xslFileNames>
<xslFile>xsl\header.xsl</xslFile>
<xslFile>xsl\modifications.xsl</xslFile>
<xslFile>xsl\MsTestSummary2008.xsl</xslFile>
</xslFileNames>
</buildReportBuildPlugin>
<buildLogBuildPlugin>
<xslReportBuildPlugin description=”MSTest Report” actionName=”MSTESTReport” xslFileName=”xsl\MsTestReport2008.xsl”/>
</buildLogBuildPlugin>
</buildPlugins>

clip_image004

Figure 2 – CruiseControl.Net Web Dashboard

clip_image006

Figure 3 – CruiseControl.NEt Project Report

clip_image008

Figure 4 – CruiseControl.Net Build Report

Advertisements

About John

Software developer, lately specialising in Full Stack Web Development using c#, ASP.Net WebAPI 2, and Angular.
This entry was posted in Development, Environment and tagged , , , , . Bookmark the permalink.

2 Responses to CruiseControl.Net – Installing and configuring with CVS, MSBuild and MSTest

  1. Nhat says:

    what is silvercodeExchangeTest.dll? I can’t find it

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s