1. Introduction (part 1)
2. Resources (part 1)
3. Installation (part 1)
3.1. Install CruiseControl.NET (part 1)
3.2. Create a CCNet Website in IIS (part 1)
3.3. Install Nunit (part 1)
4. CruiseControl.NET Server Configuration – General (part 1)
5. Structure of a ‘Project’ Configuration File (part 1)
6. Source Control Block (part 1)
7. Trigger Block (part 1)
8. Labeller Block (part 1)
9. Tasks Block
10. MsBuild Task
10.1. MSBuild and ReferencePath – CruiseControl.NET not resolving reference to Nunit
10.2. An Alternative MSBuild Logger – Christian Rodemeyer’s MsBuildToCCNet
10.3. CruiseControl.NET Webdashboard fails in finding images if not installed in virtual directory
10.4. MSBuildToCCNET reports wrong number of compiled projects
10.5. CruiseControl.NET, MsBuild Task and Resources – Assembly Linker
10.6. CruiseControl.NET, MsBuild Task and Web Application projects
11. Nunit Task
11.1. Nunit Task
11.2. Executable Task
12. Publishers Block
13. PreBuild Block
13.1. Install Nant
13.2. Nant Fundamentals
This article is the second one of a series dedicated to CruiseControl.Net.
In the first part (which you can find here) we installed it and had an overview of how to configure it.
Then we started to configure a project file: we instructed the Source Control Block to use Subversion, the Trigger Block to check it periodically and the Labeller Block to use: svnRevisionLabeller
In this second article we will see the Tasks Block and I will point out some issues that might arise and provide solutions as well.
Thanks to Frank Geerlings for making me aware of a casing problem with the xml samples.
By talking with WordPress support it came out that there was a little bug and they suggested me
how to fix the problem.
9. Tasks Block
The tasks block represents how the build of the project actually takes place.
In our example we will use an MsBuild Task to accomplish the main purpose of our project, which is to compile the versioned Visual Studio solution.
After that we will use an Executable Task to run our unit tests, if the build succeeds.
Let’s see the whole Tasks Block, at first:
<tasks>
<!-- compiles working copy -- >
<msbuild>
<executable>C:\WINDOWS\Microsoft.NET\Framework\
v2.0.50727\MSBuild.exe
</executable>
<workingDirectory>C:\develop\CCnet\project1WorkingDir
</workingDirectory>
<projectFile>DummySolution.sln</projectFile >
<buildArgs>/noconsolelogger /v:quiet
/p:Configuration=Debug
/p:ReferencePath="C:\Program Files\NUnit 2.4.7\bin"
</buildArgs>
<targets>ReBuild</targets >
<timeout>600</timeout >
<logger>c:\Program Files\CruiseControl.NET\server\
Rodemeyer.MsBuildToCCNet.dll</logger >
</msbuild>
<!-- launches nunit tests on working copy -- >
<exec>
<executable>C:\Program Files\NUnit 2.4.7\
bin\nunit-console.exe
</executable >
<buildArgs>/xml:..\project1CCnetArtifacts\nunit-results.xml
/nologo Dummy.sln.nunit
/exclude:LongRunning,AnotherCategoryName
</buildArgs>
</exec>
</tasks>
Let’s focus on the MsBuild Task first and see how we can configure and customize it:
→ top of post
→ top of paragraph
10. MsBuild Task
Let’s have a look at the meaning of the xml nodes children of the <msbuild> node:
<executable>: contains the path to the msbuild executable file. You don’t really need to set it because the default value is the standard installation path: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe.
I decided to set it explicitly just to be sure about it .
<workingDirectory>: is the directory in which MsBuild will be run, so it must be the directory containing our project’s checked out working copy. You can provide a path relative to the current project’s workinDirectory but I preferred to provide the full path. Actually, the path to the CCNET checked out working copy is the same as the <workingDirectory> field of the Source Control Block.
<projectFile>: is the name of the project to build. MsBuild accepts a Visual Studio solution file as the project file to build. Obviously the MsBuild Task accepts it as well.
<buildArgs> This row provides additional command line arguments to MsBuild. We tell it not to log events to the console (/noconsolelogger), to build the Debug configuration (/p:Configuration=Debug) and to provide a reduced output (/v:quiet).
As far as the /p:ReferencePath buildArg is concerned it is worth to talk extensively about a problem that could arise with Nunit, so have a look at paragraph 10.1.
10.1 MSBuild and ReferencePath – CruiseControl.NET not resolving reference to Nunit
It could happen that CCNET is not able to locate Nunit (or some other dependency assembly) depending on how your project file has been created by Visual Studio.
Open your project file (DummyProject.csproj) with a text editor (e.g.: Notepad++). If you find an entry as follows in it:
<Itemgroup>
<Reference Include="nunit.framework, Version=2.4.7.0,
Culture=neutral, PublicKeyToken=96d09a1eb7f44a77,
processorArchitecture=MSIL" />
....
</Itemgroup>
with no <HintPath> associated to the Nunit <Reference> it could be that CCNET will not be able to resolve that reference if you don’t register nunit.framework.dll in the server’s GAC.
You can make sure that CCNET is able to resolve the dependency by providing an alternative search path in which to look for.
Each assembly referenced in the Visual Studio project file needs to be located by MSBUild at compile time.
The location of the referenced assemblies is resolved by MSBuild by looking in several locations in a particular search order (as explained here).
We could modify the .csproj file by providing a value as a child node of the node, e.g.:
<Reference Include="DummyLibrary, Version=1.0.0.0,
Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\CommonReferencedDLLs\DummyLibrary.dll
</HintPath>
</Reference>
This approach has two drawbacks:
- the hintpath is a relative path, thus making the build success depend on the location of the project relative to the referenced assembly (this could be a problem if we reference an external assembly);
- we need to modify each Visual Studio project file by hand and we don’t want to do it!
Fortunately there’s an easy way out:
We can override all the project specific settings for path resolving by passing a ReferencePath property from the MSBuild command line.
Such property accepts as value a list of paths (MSBuild DummySolution.sln /p:”ReferencePath=<Path1;Path2;Path3>”) and it is checked by the build process before checking other locations (HintPath for example).
So the way to provide an alternative search path from the command line is to pass as argument a ReferencePath property.
This is the reason why the command line provided in the <buildArgs> field contains the ReferencePath property pointing to the Nunit install path:
/p:ReferencePath=”C:\Program Files\NUnit 2.4.7\bin”.
→ top of post
→ top of paragraph
end of paragraph 10.1
continues paragraph 10. MsBuild Task
Let’s go on with the analysis of the xml nodes children of the <msbuild> node:
<targets> specifies which targets to build in this msbuild project file. It represents the MSbuild’s /target command line argument. We set it to Rebuild (clean and build).
<timeout> is the number of seconds before assuming that the process has hung. If timeout is exceeded the process will be killed.
<logger> specifies the path to the assembly containing the logger to use to format the log output of MSbuild .
If you don’t want to use the alternative logger that I used in the configuration shown above, you can rely on the default logger as explained here and skip the following
paragraph 10.2.
To use the default logger:
- leave out the <logger> field,
- download the assembly containing the default xml logger here (find info here),
- copy the downloaded assembly (ThoughtWorks.CruiseControl.MSBuild.dll) to the folder: C:\%ProgramFiles%\CruiseControl.NET\server.
I suggest to use the alternative logger (by Christian Rodemeyer) as explained in the following paragraph. The RodeMeyer’s logger provide lighter msbuild output and his modified stylesheets provide much more readable display of such information.
10.2. An Alternative MSBuild Logger – Christian Rodemeyer’s MsBuildToCCNet
I chose to use a logger alternative to the default one: Christian Rodemeyer’s MsBuildToCCNet.
You can find it at: Improved MSBuild Integration. From there either you can download separately the assembly and all related stuff needed to correctly display the results from Rodemeyer’s logger or you can download a zip file with the whole project and source code.
In the page cited above you can find detailed instructions on how the logger works and how it should be configured.
In the current paragraph I’ll illustrate the installation process and add some useful tips for making it work.
I suggest to download the full project that comes in a zip file named: MsBuildToCCNet.zip (download here).
Unzipping the package you will have a directory named: MsBuildToCCNet. Inside this directory you will find, among the rest, a directory named Release, containing the assembly: Rodemeyer.MsBuildToCCnet.dll.
Just copy the assembly to the \CruiseControl.NET\server folder (e.g.: c:\Program Files\CruiseControl.NET\server\).
There’s another subdirectory of the MsBuildToCCNet folder, named ccnet where you can find the resources needed to correctly display the logs produced by Rodemeyer’s logger. Those resources are:
cruisecontrol.css and
msbuild2ccnet.xsl.
You need to use those two files and to configure the Webdshboard:
- Move into your CruiseControl.NET Webdashboard folder, under the path: C:\%ProgramFiles%\CruiseControl.NET\webdashboard (e.g.: c:\Program Files\CruiseControl.NET\webdashboard\) and back up the file: cruisecontrol.css.
Then replace it with the cruisecontrol.css file you found in the Rodemeyer’s MsBuildToCCNet folder (e.g.: copy MsBuildToCCNet\ccnet\cruisecontrol.css to c:\Program Files\CruiseControl.NET\webdashboard\cruisecontrol.css); - There’s a subdirectory of the CruiseControl.NET Webdashboard folder, named: xsl.
You need to copy the other resource (msbuild2ccnet.xsl) you found in the MsBuildToCCNet\ccnet folder in that directory: C:\%ProgramFiles%\CruiseControl.NET\webdashboard\xsl\; - You need to modify the dashboard.config file in the CruiseControl.NET Webdashboard folder in order to correctly show the output of the logger.
Being that we’re talking about the Webdashboard configuration I will show you all the changes you will need to do to let it work with the following three components (even if we’ll see two of them only in the following paragraphs):- MsBuildToCCNet
- Nunit integration
- FxCop integration
First of all choose a 32 x 32 jpg image representing a smiling icon and place it in the CruiseControl.NET Webdashboard folder: C:\%ProgramFiles%\CruiseControl.NET\webdashboard.
Rename the image file: your_happy_image.jpg and, when a new build succeeds, you’ll obtain a smiling icon in the Webdashboard report! (you can find a sample image here).
Then open CruiseControl.NET\webdashboard\xsl\msbuild2ccnet.xsl and go to line 24:<xsl :if test="@error_count = 0 and @warning_count = 0"> <tr> <td><img src="/ccnet/your_happy_image.jpg" alt="Happy Image
" /> Juchuu !!!</td>
</tr>
</xsl>
replace the img src attribute: /ccnet/your_happy_image.jpg with /your_happy_image.jpg if you configured iis with a new website for the webdashboard instead of a virtual directory. If you’re usign the default virtual directory named ccnet, don’t modify that row.
Next you need to locate the field: <buildPlugins> in C:\%ProgramFiles%\CruiseControl.NET\webdashboard\dashboard.config and arrange or delete its children nodes in order to obtain the following configuration (remember to back up the file first):<buildplugins> <buildreportbuildplugin> <xslfilenames> <xslfile>xsl\header.xsl</xslfile> <xslfile>xsl\modifications.xsl</xslfile> <xslfile>xsl\msbuild2ccnet.xsl</xslfile> <xslfile>xsl\unittests.xsl</xslfile> <xslfile>xsl\compile.xsl</xslfile> <xslfile>xsl\fxcop-summary.xsl</xslfile> </xslfilenames> </buildreportbuildplugin> <buildlogbuildplugin /> <xslreportbuildplugin description="NUnit Details" actionName="NUnitDetailsBuildReport" xslFileName="xsl\tests.xsl" /> <xslreportbuildplugin description="NUnit Timings" actionName="NUnitTimingsBuildReport" xslFileName="xsl\timing.xsl" /> <xslreportbuildplugin description="FxCop Report" actionName="FxCopBuildReport" xslFileName="xsl\FxCopReport.xsl" /> </buildplugins>As you can see, such configuration includes also stylesheet files for nunit and fxcop integration. We will soon configure the server to integrate those components.
→ top of post
→ top of paragraph
end of paragraph 10.2
continues paragraph 10. MsBuild Task
While adding the smiling image in the previous paragraph we had to change the path in the xsl file.
The same problem could arise with other stylesheet files if you configured the webdashboard to be a website instead that a virtual directory named ccnet.
Have a look at the next paragraph for details:
10.3. CruiseControl.NET Webdashboard Fails in Finding Images if Not Installed in Virtual Directory
If you unchecked ‘Create virtual directory in IIS for Web dashboard’ as shown in part 1 of this tutorial at 3.1. Install CruiseControl.NET and installed the Webdashboard as a new website as shown in the paragraph: 3.2. Create a CCNet Website in IIS, the webdashboard could have problems in resolving image paths.
You will realize it as soon as you will configure the server to integrate nunit or fxcop (will see it in following paragraphs).
To make sure not to have this problems you must modify the following files:
xsl\tests.xsl
xsl\fxcop-summary.xsl
under: C:\%ProgramFiles%\CruiseControl.NET\webdashboard\
you have to replace all the paths relative to the root of the website with relative paths, e.g:
in the file: xsl\tests.xsl you should replace all entries like:
eImg.src = "<xsl :value-of select="$applicationPath"/>/images/arrow_minus_small.gif";
with:
eImg.src = "<xsl :value-of select="$applicationPath"/>images/arrow_minus_small.gif";
and entries like:
<img src="{$applicationPath}/images/fxcop-error.gif"/>
with:
<img src="{$applicationPath}images/fxcop-error.gif"/>
that is, you simply need to delete the leading ‘forward slash’ at the beginning of the path (just before the ‘images’ folder name).
you need to accomplish the same task with the file xsl\fxcop-summary.xsl, e.g.:
you should replace entries like:
<xsl :attribute name="src"><xsl :value-of select="$applicationPath" />/images/fxcop-critical-error.gif</xsl>
with:
<xsl :attribute name="src"><xsl :value-of select="$applicationPath" />images/fxcop-critical-error.gif</xsl>
Actually, you should find all paths to images in those two files and delete the leading forward slash.
→ top of post
→ top of paragraph
end of paragraph 10.3
continues paragraph 10. MsBuild Task
Back to the MSBuildToCCNET alternative Logger for MsBuild, I will explain now why I decided to recompile the source code instead of using the assembly provided: MsBuildToCCNet\Release\Rodemeyer.MsBuildToCCnet.dll
10.4. MSBuildToCCNET Reports Wrong Number of Compiled Projects
I found that MsBuildToCCNet reported the wrong number of projects in the webdashboard in the page reporting the details of the last build.
There’s a row that sounds like the following, displaied in that page:
‘15 Projects built with 2 warnings’
Looking at the source code (in the file: Logger.cs) I realized that the list of Project type instances includes the solution file (DummySolution.sln) and a Project object named “MSBuild“, somehow representing the MsBuild process.
Appearently this is the reason why the reported number of projects is wrong.
I still haven’t tried to contact the author so I don’t know very well how the Logger is supposed to work as far as this count is concerned.
As a workaround I modified the following row:
w.WriteAttributeString("project_count",
XmlConvert.ToString(projects.Count));
turning it into:
w.WriteAttributeString("project_count",
XmlConvert.ToString(projects.Count - 2));
in the ‘WriteLog(XmlWriter w)’ method (file: Logger.cs at row 104).
This seems having fixed the problem with no side effects.
→ top of post
→ top of paragraph
end of paragraph 10.4
continues paragraph 10. MsBuild Task
You could have problems running msbuild task if your server machine (the one in which you installed CruiseControl.NET) is not updated with all the software installed in a developer workstation. Let’s see which problems could arise:
10.5. CruiseControl.NET, MsBuild Task and Resources – Assembly Linker
If you want to provide localization for any of your projects or somehow use resources files (.resx) you will get an error during the build on the CruiseControl.NET server if MsBuild is not able to locate the Assembly Linker.
The error should look something like:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1950,9): error MSB3011: “C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\AL.exe” was not found. Either 1) Install the .NET Framework SDK, which will install AL.exe. Or 2) Pass the correct location of AL.exe into the “ToolPath” parameter of the AL task.
AL.exe is used to produce the satellite assemblies and the executable file is placed in the .NET framework directory.
But Al.exe is a .Net Framework SDK tool. It is not included in .Net Framework 2.0 runtime installation.
You need to install the .NET framework SDK on the server machine if you don’t want to encounter this problem.
If you want to solve this particular issue in a tricky way without installing the whole SDK, you can copy al.exe.config e al.exe from a developer workstation and place them in the C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 directory on the server machine.
This is how I solved the problem but I suggest you to install the .NET framework SDK on the server machine.
→ top of post
→ top of paragraph
10.6. CruiseControl.NET, MsBuild Task and Web Application projects
A particular note is due for Web projects.
Updating Visual Studio 2005 you get the SP1. Together with the Service Pack 1 for Visual Studio you get the WebApplication project template.
Such template lets us add a new kind of project to our solution: a web site project structured exactly like any other Visual Studio project.
So you can quit creating new websites (File –> New –> Web Site…) and start creating new WebApplication projects (File –> New –> Project… and then choose ‘ASP.NET Web Application‘).
In order to use WebApplication projects you need to have Visual Studio installed on your machine and the WebApplication project plugin (that comes with the Visual Studio 2005 SP1).
If the server in which CruiseControl.NET server is running is not a develpment workstation you will get an error when trying to build a WebApplication project, beacuse you miss those two prerequisites.
You can easily fix this problem: you simply need to copy the file: Microsoft.WebApplication.targets that you can find under:
“C:\Program Files\MSBuild\Microsoft\VisualStudio\v8.0\WebApplications\”
from a development workstation and paste it to the corresponding path on the server machine (creating the directories in the path if needed).
Additionally, if you’re using an ASP.NET AJAX Enabled WebApplication as the web project template you need to install the aspnet-ajax extensions as well.
You can find the installer (ASPAJAXExtSetup.msi) for .NET framework 2.0 here
→ top of post
→ top of paragraph
11. Nunit Task
The second Task Block that you find in the xml fragment above is an Executable Task used to instruct CruiseControl.NET to run unit tests with Nunit.
At first I tried to use a Nunit Task Block but I soon realized that it was not good for me because it was not possible to provide arguments to the task that should be used as arguments of the Nunit command-line executable.
This is a problem because there’s no way to let the Nunit task be aware of Nunit categories.
For those who don’t know, Nunit lets you specify a ‘Category‘ attribute in test methods, with the following syntax:
[Test]
[Category("LongRunning")]
public void VeryLongTest()
{ /* ... */ }
This attribute allows you to instruct Nunit to treat all the methods belonging to the same category in the same way.
Usually what we want to do is to exclude a cluster of tests from running.
Typically we exclude tests that take too much to run, using the following syntax with the nunit command-line tool:
nunit-console.exe /exclude:LongRunning,AnotherCategoryName
You can configure excluded categories in nunit GUI as well, by clicking the ‘Categories‘ tab in the top left corner.
A list of available categories will be shown. Just select the categories of interest and click the Add button.
Then check the Exclude these categories checkbox at the bottom of the page and run the nunit project.
It is very useful to be able to exclude some categories of tests from the continuous integration environment, still being able to run them on developer machines.
This is the reason why I recently submitted a patch to CruiseControl.Net adding support for Nunit categories.
It’s not included in the official release yet, because I submitted it too late for this purpose.
However you can find it in the current build which is publicly available at: ccnetlive. The patch is included starting from build: 3591.
So now you have two chances to use categories:
- If you really want to use the last officially released version, read the paragraph 11.2 about how to use an Executable Task (the method described can be useful also if you want to use any other unsupported Nunit command line argument);
- Instead if you can download the latest build from ccnetlive you will be able to specify categories inside the Nunit Task block, as explained in paragraph 11.1
11.1. Nunit Task
If you downloaded the most recent build and followed the installation instructions (see: 3. Installation) you can go on reading this paragraph.
If you installed the official release or a build older than 1.4.0.3591, you can still modify your installation with the following instructions:
download the zipped package (here) or source code. Unzip it in a temporary directory and locate the assembly: ThoughtWorks.CruiseControl.Core.dll (which, for the zip package, is in the directory: ’server’).
Copy and replace it to the original one in your CCNET installation directory (back up the original one first) that should be: Program Files\CruiseControl.NET\server.
That’s it! Now you can use the CruiseControl.NET’s Nunit Task Block also for specifying Nunit categories (see: Nunit categories for reference).
It is possible to specify a list of the categories of tests that we want to be excluded.
It is possible, as well, to specify a list of the only categories that we want to be included as allowed by the Nunit Command-line or GUI interface.
The configuration syntax for the Nunit task becomes:
<nunit>
<path>C:\Program Files\NUnit 2.4.7\bin\nunit-console.exe
</path>
<assemblies>
<assembly>Dummy.sln.nunit</assembly>
</assemblies>
<excludedCategories>
<excludedCategory>LongRunning</excludedCategory>
<excludedCategory>Category 2</excludedCategory>
</excludedCategories>
</nunit>
for excluded categories, or:
<nunit>
<path>C:\Program Files\NUnit 2.4.7\bin\nunit-console.exe
</path>
<assemblies>
<assembly>Dummy.sln.nunit</assembly>
</assemblies>
<includedCategories>
<includedCategory>LongRunning</includedCategory>
<includedCategory>Category 2</includedCategory>
</includedCategories>
</nunit>
for included categories. You can find the official reference at this page on the official website.
The Nunit task output log file is automatically integrated in the CCNET build results.
So you don’t need to specify the Merge task (needed if you use the procedure explaine in paragraph 11.2 instead of this one) in the Publishers block as explained in paragraph 12:
<merge>
<files>
<file>..\project1CCnetArtifacts\nunit-results.xml</file>
</files>
</merge>
Instead you still need to delete the previous Nunit log file before each build process as explained in the paragraph 13 – PreBuild Block.
→ top of post
→ top of paragraph
11.2. Executable Task
If you’re working with the official release of CruiseControl.Net (release 1.4) Nunit Task Block syntax only allows you to specify the target solution and little more. In our example it would be:
<nunit> <path>C:\Program Files\NUnit 2.4.7\bin\nunit-console.exe </path> <assemblies> <assembly>Dummy.sln.nunit</assembly> </assemblies> </nunit>
where Dummy.sln.nunit is the Nunit project file for our solution.
The solution I strongly suggest is to replace the Nunit Task with an Executable Task like the one shown below:
<exec>
<executable>
C:\Program Files\NUnit 2.4.7\bin\nunit-console.exe
</executable>
<buildArgs>/xml:..\project1CCnetArtifacts\nunit-results.xml
/nologo Dummy.sln.nunit
/exclude:LongRunning,AnotherCategoryName
</buildArgs>
</exec>
You only need to specify the full path to the Nunit command-line executable file in the <executable> field and the command-line arguments in the <buildArgs> field.
In the <buildArgs> field you specify arguments as if provided directly to nunit-console.exe:
- specify the path to the file in which nunit will write its output: /xml:..\project1CCnetArtifacts\nunit-results.xml.
The file should be produced in the artifactDirectory of the current CCNET project.
By default the executable run by an executable task is run in the Project Working Directory, so the path to the output file is relative to such directory. - You can pass many things as Nunit targets (assemblies, Visual Studio projects or Nunit project files). I suggest to create an Nunit project and pass it as argument to nunit-console.exe as shown in the sample above (where the nunit project file is called: Dummy.sln.nunit).
- you can then add: /exclude:LongRunning,AnotherCategoryName thus excluding unwanted tests.
Specifying the name of the output file is not enough.
In order to make the output written by nunit in the file nunit-results.xml (arbitrary name specified in the buildArgs tag), available to CruiseControl.NET we need to use a File Merge Task.
If we used Nunit task the output file would have been automatically merged with other output for CruiseControl.NET.
Using the Executable Task we need to explicitly configure CruiseControl.NET to merge the Nunit output file in the log file parsed by CruiseControl.NET.
We will tell CruiseControl.NET to do it at the end of the build process, namely in the Publishers section.
→ top of post
→ top of paragraph
12. Publishers Block
We will add a File Merge Task at the beginning of the Publishers section. You can see below the publishers section as it is defined in our project configuration file:
<publishers>
<merge>
<files>
<file>..\project1CCnetArtifacts\nunit-results.xml
</file>
</files>
</merge>
<xmllogger />
<statistics />
<modificationHistory onlyLogWhenChangesFound="true" />
<artifactcleanup cleanUpMethod="KeepLastXBuilds"
cleanUpValue="20" />
...
</publishers>
The File Merge Task specifies the paths to the files that we want to be merged by the Xml Log Publisher Task with the rest of its own output (you don’t need to specify nunit output file if you used the Nunit Task as in paragraph 11.1. Nunit Task).
All of this output is placed by default in the buildlogs directory under the Project’s Artifact Directory.
So the File Merge Task should appear before the Xml Log Publisher Task in the publishers section.
The Xml Log Publisher Task (‘xmllogger‘) is needed for making the web dashboard work correctly.
The ‘statistics‘ field collects and updates statistics for each build. You can see them clicking: View Statistics on the left side of the Web Dashboard.
The ‘modificationHistory‘ field logs all the modifications for each build. With onlyLogWhenChangesFound you can choose to log info only for builds happened when changes take place (not for forced builds). You can see the modification history by clicking: View Modification History on the left side of the Web Dashboard.
I then added an ‘artifactcleanup‘ field in order to keep memory of the last 20 builds only.
This task allows us to choose between two clean up modes of the past build logs:
- deleting logs older than a specified number of days
- keeping only a specified number of logs: the more recent ones (cleanUpMethod=”KeepLastXBuilds”)
In the sample above we typed the second choice specifying 20 as cleanUpValue thus telling CruiseControl.NET to keep the log files for the last 20 builds only.
→ top of post
→ top of paragraph
13. PreBuild Block
There’s another issue to solve when integrating Nunit using either an Exec Task or the Nunit Task: the Nunit log file is not deleted after the build succeeds or fails.
So upon the next build we’ll still have the old Nunit log file until the Task running Nunit is executed.
To understand what I’m going to explain now, keep in mind that if a task in the Tasks Block fails all the subsequent tasks in the block will be skipped while the tasks in the Publishers Block will be executed.
If, during the next build, the MSBuild Task fails, the Exec Task (Nunit Task) launching Nunit isn’t executed at all so the File Merge Task will merge the previous Nunit log file with the current Xml Log Publisher output, thus leading to an incorrect report: still displaying the Nunit results relative to the previous build.
We would obtain the current MSBuild report but the old Nunit report.
This behavior can lead to misunderstanding of the results so it is a good practice to delete the old Nunit log file before every new build takes place.
The place to accomplish this task is the PreBuild Block.
I used a Nant build file to drive the steps needed to obtain the desired result (simply delete a file if it exists).
13.1. Install Nant
You need to install the Nant Build tool on the server machine.
Just download the zip package: nant-0.85-bin.zip from here and unzip it into the folder: C:\Program Files\Nant.
13.2. Nant Fundamentals
Nant is a build tool driven by xml configuration files (Nant build files).
When you call nant.exe from the command line and you don’t specify a build file (you can specify one passing as argument: -buildfile:pathToDir\FileName.build) NAnt looks for a file ending with .build (e.g.: NAnt.build) in the current directory. If it finds such file, it uses it as the reference for the tasks to execute.
The file structure is shown in the following sample xml file:
< ?xml version="1.0"?>
<project name="dummy" default="target1" basedir=".">
<description>dummy project</description>
<target name="target1" description="target1 description">
... (a list of Nant tasks will be placed here)
</target>
<target name="target2" description="target2 description">
<delete file="pathToFile\FileName"
failonerror="false" />
... (a list of other Nant tasks will be placed here)
</target>
</project>
A build file contains one <project> field with one or more children <target> fields each containing different Nant tasks (e.g.: the <delete> task).
When invoking nant.exe you can specify the name of the target to be executed and Nant will execute all the tasks contained in that target. If you don’t provide a target, the default one will be executed (i.e. the one specified in the ‘default‘ attribute of the <project> field).
end of paragraph 13.2
continues paragraph 13. PreBuild Block
Once you’ve got Nant installed on the server machine you have to create a file named nant.build and place it, for convenience, in the directory in which you placed all the CruiseControl.NET related stuff (in this example: C:\develop\CCnet).
At the moment we need just one target to delete Nunit log files. Later we will add another target.
The actual file content is the following:
< ?xml version="1.0"?>
<project name="Dummy" default="cleanNunit" basedir=".">
<description>CCNET Tasks</description>
<target name="cleanNunit"
description="removes nunit log file">
<delete file="${CCNetArtifactDirectory}\nunit-results.xml"
failonerror="false" />
</target>
</project>
When we tell Nant to execute the ‘cleanNunit‘ target, the delete task will be executed and the nunit-results.xml file will be deleted.
We use one of the environment variables provided by CCNET to retrieve the path to the artifact directory: ${CCNetArtifactDirectory} so this Nant build file will only work when run from CruiseControl.NET.
In the Prebuild Block we will instruct CruiseControl.NET to run a Nant task by adding a CruiseControl.NET Nant Task Block.
Such block lets us instruct CruiseControl.NET to execute Nant and lets us specify a Nant build file and the list of Nant targets to execute.
Remember that we named the build file: nant.build and we placed it in the directory: C:\develop\CCnet.
Now we provide this information to the CruiseControl.NET Nant Task Block as shown in the following example:
<prebuild>
<!-- clean nunit output to avoid CCNET reporting
about previous build tests if current build fails -->
<nant>
<executable>C:\Program Filse\Nant\bin\nant.exe
</executable>
<baseDirectory>C:\develop\CCnet</baseDirectory>
<nologo>false</nologo>
<buildFile>nant.build</buildFile>
<targetList>
<target>cleanNunit</target>
</targetList>
</nant>
</prebuild>
the <executable> field specifies the path to the version of nant.exe you want to run,
the <baseDirectory> specifies the directory to run the NAnt process in,
<nologo> passes the -nologo argument to the Nant command line,
<buildFile> specifies the path to the build file to use (relative to the <baseDirectory>),
<targetList> is used to specify a list of targets, each one in a <target> field.
Now we can be sure that each build has the Nunit log file deleted before being executed.
→ top of post
→ top of paragraph
<< CruiseControl.Net Tutorial – Part 1



[...] CruiseControl.Net Tutorial – Part 2 – Matteo continues his series on Cruise Control Setup and configuration with part two, covering the actual build and publish. [...]
Tutorial is excellent. One stop information required to setup CruiseControl.Net I just followed the tutorial and i don’t have to look elsewhere because of any issues occurred in between. All the blocks are nicely explained.
Tones of thanks for this.
You’re welcome,
I’m very happy that you find it useful.
I will add some more details when I will add part 3.
Stay tuned!
Good aritcle!
Good aritcle!
I have a problem
I don’t now what testing tool use with the CruiseControl
for web applications with Ajax (C#) .Net
can you suggest me one?
pd:sorry my bad ingles
Hello Lorena,
If I guessed your question right, you’re looking for a tool to test ajax enabled web pages.
I heard about a tool serving this purpose. I still didn’t try it but it seems to be good.
It allows you to write web tests from inside Nunit and supports both Internet Explorer and FireFox.
It could be the tool for you.
The name is Watin and you can find it here: http://watin.sourceforge.net/
Matteo
Matteo
This is an excellent article. I was completely new to CruiseControl and was having trouble gathering all the relevant information to get me up to speed. I then stumbled upon your blog and all became clear. Can’t wait to see Part 3
Many thanks indeed.
Col
Hello Colin,
thank you very much for appreciating my article!
I’m sorry for the delay in publishing part 3, I’m having hard time at work in these days.
I will try to be quicker in the next days and I hope you will like it when published.
Matteo
Hi I am facing a issues with the cruise control results. CC is showing up a build as failed when it is a success. Is there any fix for this? How can I sort this issue?
Thanks for your post it was simply superb.
Hello Kishore,
you should tell me something more about the problem you’re facing.
I will be glad to help you if I can.
It could be useful if you post an example of your configuration or the relevant point of your log file.
I sent you an email about it.
Thank you for the compliments
Thanks very much for the article. Very useful.
brilliant stuff. thank you! looking forward to part 3.
I’m very sorry for the delay, I was busy at work in the past months.
There are news, though:
I enhanced Nunit task for CCNET and they accepted my modifications (I will update this post to describe the new behavior),
I will soon post third part of this series,
I’m preparing a new article series about another interesting software.
Thank you for the feedbacks and for the patience to everyone
Parts one and two have been very helpful in my quest to implement continuous integration. Thank you for making this available in a simple to follow presentation. I am desperately awaiting installment number 3.
Is it possible to use the cruisecontrol.net executable task to delete a directory?
I tried this:
rmdir
&MyWorkDirectory;
TempFolder /S /Q
0
but I get an error:
ThoughtWorks.CruiseControl.Core.Tasks.BuilderException: Unable to execute: FileName: [rmdir] — Arguments: [TempFolder /S /Q] — WorkingDirectory: [C:\Continuous Integration\Project]
oops, my comment had it’s tags removed – that makes it tough to see what I tried to do – I’ll try it again…Here is my <exec> block:
<exec>
<executable>rmdir</executable>
<baseDirectory>&MyWorkDirectory;</baseDirectory>
<buildArgs>TempFolder /S /Q</buildArgs>
<successExitCodes>0</successExitCodes>
</exec>
I hope html encoding it will make it show up properly here
I figured out how to remove a directory using the executable task:
<exec>
<executable>cmd</executable>
<baseDirectory>&MyWorkDirectory;</baseDirectory>
<buildArgs>/C rmdir TempFolder /S /Q</buildArgs>
<successExitCodes>0</successExitCodes>
</exec>
Hello Joel,
I’m happy that you found the solution…sorry for coming back here too late to answer
Wish I had found this earlier.
I wasted a lot of time tracking down that NUnit didn’t refresh on failures.
Looked like everything was going great, but the test results weren’t changing.
Hey ,
thanks a lot for the information.
Could you please mail me all the stuff that you have related to this cruisecontrol ???
Thanking in anticipation
Regards,
Ajit
Hi. Sorry to interupt this blog post and your reading but would you mind voting for best ROCK BAND/INDIVIDUAL?
My vote is for Pearl Jam and Your?
http://www.slideshare.net/warezforumadmin/vote-for-best-rock-band-1963461
Hi,
CruiseControl is there to help us get the work done and you made it easy enough for me to actually save time implementing it. There a cruel lack of documentation for typical uses of ccnet and your article is just great doing that!
Thanks a lot!