·舟山詩詞·淘海洗玉集 – My Poems, and etc.

CCNet vs. CruiseControl

with 22 comments

Set once and let it go, this is how Continuous Integration works for automated build process along with development cycle. For a large number of projects, the maintenance for such continously integrated build environment could be complicate and cumbersome. This article will provide and discuss sample config files from practice experience to make easy using CruiseControl.NET and CruiseControl with subversion repository. For comparison of all other similar products, see ThoughtWorks CI Feature Matrix.



CCNET (CruiseControl.NET) starts with ccnet.config:

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE cruisecontrol SYSTEM "file:ccnet_definitions.dtd">

<cruisecontrol xmlns:cb="urn:ccnet.config.builder">
  <cb:include href="ccnet_definitions.xml" xmlns:cb="urn:ccnet.config.builder"/>

  <queue name="$(computername)" duplicates="ApplyForceBuildsReAdd" />
  <cb:include href="ccnet_Project.Standard_Solution.xml" xmlns:cb="urn:ccnet.config.builder"/>

  <cb:include href="ccnet_MyProject.xml" xmlns:cb="urn:ccnet.config.builder"/>

In order to maintain CCNET config and projects in clear XML code, the ccnet.config in above example takes advantage of CCNET powerful preprocessor features. There are three types of CCNET configuration preprocessors: constant (including text/variable and nodeset XML fragment), nested expansion (defining a class whose instance can take parameters), and include file (<cb:include />).

Including external config files helps putting constant/variable definitions, project definitions, and reusable XML pieces together in an organized structure, so that ccnet.config can be read in a from-top-to-down order while presenting high-level view in the main config. Another advanced use of include files is to allow editing definition or project file individually without touching ccnet.config. CCNET has the ability to notice any include file changed and reload ccnet.config automatically.

Like writing a program, the first thing in design is to define constants, variables, and reusable functions (or templates) that can be shared across the projects. These are all implemented by <cb:define /> in CCNET. Constants and XML fragments can be defined by DTD, such as in XHTML DTDs and following sample of ccnet_definitions.dtd included in ccnet.config.

<!ENTITY dir_ccnet "$(ProgramFiles)\CruiseControl.NET">
<!ENTITY dir_ccnet_server "$(ProgramFiles)\CruiseControl.NET\server">
<!ENTITY dir_ccnet_artifacts "$(ProgramFiles)\CruiseControl.NET\server\projects">
<!ENTITY dir_svn "$(ProgramFiles)\CollabNet Subversion Server">
<!ENTITY dir_svn_target "\\\svnbuilds">
<!ENTITY dir_dotnet "$(SystemRoot)\Microsoft.NET\Framework\v3.5">
<!ENTITY dir_msvs "$(ProgramFiles)\Microsoft Visual Studio 9.0">

<!ENTITY svn_server "svn://">
<!ENTITY auth_svn "<username>svn_user</username><password>svn_password</password>" >

<!ENTITY exec_devenv "<executable>&dir_msvs;\Common7\IDE\</executable>" >
<!ENTITY exec_nmake "<executable>&dir_msvs;\VC\bin\nmake.exe</executable>" >
<!ENTITY exec_msbuild "<executable>&dir_dotnet;\MSBuild.exe</executable>" >
<!ENTITY exec_svn "<executable>&dir_svn;\svn.exe</executable>" >

<!ENTITY url_ccnet "http://localhost/ccnet">

However, entity definition has its limitation in use (such as in string value of a property) and modifying a system file included by <!DOCTYPE > cannot trigger ccnet.config to reload. In CCNET, <cb:define /> is recommended to perform the same and even better job. The following sample illustrates syntax of defining text constant (variable) and nodeset (xml fragment). The third usage of <cb:define />, nested expansion, is for reusable class that can take parameters by instance, such as defining a project template.

<cb:config-template xmlns:cb="urn:ccnet.config.builder">
<!--# Preprocessor: Text Constants -->
  <cb:define const_name="value" /> <-- defines $(const_name), or <cb:const_name/> -->
  <cb:define dir_ccnet="$(ProgramFiles)\CruiseControl.NET" />
  <cb:define dir_ccnet_server="$(dir_ccnet)\server" />
  <cb:define dir_ccnet_artifacts="$(dir_ccnet_server)\projects" />
  <cb:define dir_ccnet_buildlogger="$(dir_ccnet)\server\ThoughtWorks.CruiseControl.MsBuild.dll" />
  <cb:define dir_dotnet="$(SystemRoot)\Microsoft.NET\Framework\v3.5" />
  <cb:define dir_svn="$(ProgramFiles)\CollabNet Subversion Server" />
  <cb:define dir_svn_source="c:\svn_checkout" />
  <cb:define dir_svn_builds="d:\svn_builds" />
  <cb:define dir_svn_target="\\\svnbuilds" />
  <cb:define dir_system32="$(SystemRoot)\system32" />
  <cb:define dir_msvs="$(ProgramFiles)\Microsoft Visual Studio 9.0" />

  <cb:define svn_username="svn_username" />
  <cb:define svn_password="svn_password" />

  <cb:define url_svn_target="file://///" />
  <cb:define url_ccnet="http://localhost/ccnet" />

<!--# Preprocessor: Nodeset Constants -->
  <cb:define name="xml_default_extlink">
    <externalLink name="CCNET Builds [Ctrl+Click to open in Explorer]" url="$(url_svn_target)" />
  <cb:define name="xml_logger">
    <xmllogger logDir="$(dir_ccnet_server)\projects\$(project)" />

  <cb:define name="auth_svn">
  <cb:define name="exec_devenv">
  <cb:define name="exec_nmake">
  <cb:define name="exec_vcvars">
  <cb:define name="exec_msbuild">
  <cb:define name="exec_svn">

<!--# Preprocessor: Nested Expansions (see other ccnet_*.xml)
  <cb:define name="xml_element"><some_element property="$(var1)" /><more>$(var2)</more></cb:define>
  <cb:xml_element var1="value1" var2="value2" />


The use of definitions in CCNET is easy to understand from above sample config file. First of all, any system environment variables can be referenced by $(env_var), where $(env_var) is an environment variable accessible in CCNET runtime context. For example, if CCNET is started by ccnet.exe manually in a Command Prompt window, all system variables and logon user variables should be available; otherwise, if CCNET is started in service.msc, only system variables can be used.

Once a CCNET constant/variable (<cb:define var_name="text" />) or XML fragment (<cb:define name="element_name" >...</cb:define>) is defined, it can be referenced immediately afterward thru whole CCNET runtime environment. The constant/variable can be referenced as a string by $(var_name), or <cb:var_name />. The XML fragment must be referenced by <cb:element />. All <cb:define /> are global definitions. To control the scope of a preprocessor definition, use <cb:scope />. See configuration preprocessors.

Next, let’s take a look at how to use CCNET nested expansions and parameters of preprocessor definition to create a project template. This template can be used to meet the following conditions:

  • All project properties can be initiated by an instance of the template
  • There is only one build target path needed to be published
  • There is only one developer and who will be in notification for all build states
  • The project can be built by a MS Visual Studio 2008 solution file

Similar to ccnet_definitions.xml, ccnet_Project.Standard_Solution.xml uses <cb:config-template /> but only defines one XML fragment named “project_template_solution“.

<?xml version="1.0" encoding="utf-8" ?>
<cb:config-template xmlns:cb="urn:ccnet.config.builder">
<cb:define name="project_template_solution">
<project name="$(project_name)" queue="$(project_queue)" queuePriority="0">

  <labeller type="svnRevisionLabeller">
    <cb:auth_svn />
  <labeller type="lastChangeLabeller"><prefix>$(project_name)-</prefix></labeller>
    <!--NOTE: build machine must sync clock with svn server!!!-->
    <intervalTrigger buildCondition="IfModificationExists" seconds="$(project_checkTime)" initialSeconds="60" />
  <sourcecontrol type="svn">
    <cb:auth_svn />
    <cb:exec_svn />
    <timeout units="seconds">$(project_checkTime)</timeout>

      <cb:exec_msbuild />
      <buildArgs>/noconsolelogger /p:Configuration=Release</buildArgs>

    <cb:xml_logger project="$(project_name)" />


    <cb:include href="ccnet_email.xml" xmlns:cb="urn:ccnet.config.builder" />
        developer_name="Developer" developer_alias="$(project_developer)"



Different from ccnet_definitions.xml, ccnet_Project.Standard_Solution.xml also uses some variables that have never been defined, such as $(project_name), $(project_path), and etc., basically anything with “project_” prefix in this example. This is the exclusive feature of CCNET preprocessor that allow all these variable dynamically bound to an instance of the template when it is used. In ccnet.config, after ccnet_Project.Standard_Solution.xml is loaded, a project file ccnet_MyProject.xml comes after to initiate a project configuration based on the template. Here is code:

<cb:config-template xmlns:cb="urn:ccnet.config.builder">
    project_name="My Project"
    project_category="My Category"


The properties defined in “My Project” configuration makes the template used in complete. Actually, the property names after cb:project_template_solution may not be necessary matching what have been defined in the template. At least CCNET does not check if a referenced constant or variable is predefined. Undefined constant/variable will be replaced by empty string (- be caution that this could cause exception at the runtime). And any property defined in the instance but not used in the template will be ignored (e.g. project_svnPath).

CCNET preprocessor config template can be nested. Here is the file of ccnet_email.xml that has been included in ccnet_Project.Standard_Solution.xml:

<cb:config-template xmlns:cb="urn:ccnet.config.builder">

  <cb:define name="ccnet_email">
    <email from="" 
           mailhost="" includeDetails="TRUE" useSSL="FALSE"
           subjectPrefix="CCNET:" description="CruiseControl.NET E-mail Notification ">
        <user name="Builder" group="Builder" address=""/>
        <user name="$(developer_name)" group="Developer" address="$(developer_alias)"/>
        <user name="Build Request" group="Supervisor" address=""/>
        <user name="Admin" group="Admin" address=""/>
        <group name="Admin" notification="Failed"/>
        <group name="Builder" notification="Success"/>
        <group name="Developer" notification="$(notification)"/>


        <subject buildResult="Broken" value="Build Failed - ${CCNetProject} - [Broken] :: ${CCNetBuildCondition}" />
        <subject buildResult="StillBroken" value="Build Failed - ${CCNetProject} - [StillBroken] :: ${CCNetBuildCondition}" />
        <subject buildResult="Fixed" value="Build Success - ${CCNetProject} - [Fixed] :: ${CCNetBuildCondition}" />
        <subject buildResult="Exception" value="Build Failed - ${CCNetProject} - [Exception] :: ${CCNetBuildCondition}" />
        <subject buildResult="Success" value="Build Success - ${CCNetProject} - [Success] :: ${CCNetBuildCondition}" />

  <!--# after <cb:include href="ccnet_email.xml" />, define following properties:
        developer_name  - developer name
        developer_alias - developer email alias
        notification    - notification type: Always|Change|Failed|Success|Fixed

For label variables used in <subjectSettings />, please refer to CCNET Email Publisher.

The last thing left uncovered in the project template is “svnRevisionLabeller”. This is a modified plugin based on original svnrevisionlabeller. The code (SvnRevisonLabeller.cs) is attached below:

 * Class Name:  SvnRevisionLabeller
 * Description: Subversion functions used in NAnt
 * Requisite:   Reference to NAnt.Core.dll
 * Notes:       See
using System;
using System.Xml;
using Exortech.NetReflector;
using ThoughtWorks.CruiseControl.Core;
using ThoughtWorks.CruiseControl.Core.Util;

namespace ccnet.SvnRevisionLabeller.plugin
 /// <summary>
 /// Generates label numbers using the Subversion revision number.
 /// </summary>
 /// <remarks>
 /// This class was inspired by Jonathan Malek's post on his blog 
 /// (<a href="">CruiseControl.NET and Subversion Revision Numbers using NAnt</a>),
 /// which used NAnt together with Subversion to retrieve the latest revision number. This plug-in moves it up into 
 /// CruiseControl.NET itself, so that you can see the latest revision number appearing in CCTray. The label can
 /// then be retrieved from within NAnt by accessing the property <c>${CCNetLabel}</c>.
 /// </remarks>
 public class SvnRevisionLabeller : ILabeller
  #region Private members

  private int major;
  private int minor;
  private string _url;
  private string executable;
  private string prefix;
  private string username;
  private string password;
  private const string RevisionXPath = "/log/logentry/@revision";


  #region Constructors

  /// <summary>
  /// Initializes a new instance of the <see cref="SvnRevisionLabeller"/> class.
  /// </summary>
  public SvnRevisionLabeller()
   major = 1;
   minor = 0;
   executable = "svn.exe";
   prefix = String.Empty;


  #region Public methods

  /// <summary>
  /// Returns the label to use for the current build.
  /// </summary>
  /// <param name="resultFromLastBuild">IntegrationResult from last build used to determine the next label</param>
  /// <returns>the label for the new build</returns>
  public string Generate(IIntegrationResult resultFromLastBuild)
   // Get the last revision from the Subversion repository
   int svnRevision = GetRevision();

   // Get the last revision from CruiseControl
   Version version = ParseVersion(svnRevision, resultFromLastBuild);

   // If the revision number hasn't changed (because no new check-ins have been made), increment the build number;
   // Otherwise, reset the build number to 0
   int revision = (svnRevision == version.Build) ? version.Revision + 1 : 0;

   // Construct a new version number, adding any specified prefix
   Version newVersion = new Version(major, minor, svnRevision, revision);

            if (major == 0 && minor == 0)
                // <major>0</major><minor>0</minor> must be explicitly defined
                // assume we only care about subversion revision - 2008-11-18
                return prefix + svnRevision;
            else // keep original usage for a 4-field version format
                return prefix + newVersion;

  /// <summary>
  /// Runs the task, given the specified <see cref="IIntegrationResult"/>, in the specified <see cref="IProject"/>.
  /// </summary>
  /// <param name="result"></param>
  public void Run(IIntegrationResult result)
   result.Label = Generate(result);


  #region Public properties

  /// <summary>
  /// Gets or sets the major build number.
  /// </summary>
  /// <value>The major build number.</value>
  [ReflectorProperty("major", Required=false)]
  public int Major
    return major;
    major = value;

  /// <summary>
  /// Gets or sets the minor build number.
  /// </summary>
  /// <value>The minor build number.</value>
  [ReflectorProperty("minor", Required=false)]
  public int Minor
    return minor;
    minor = value;

  /// <summary>
  /// Gets or sets the repository URL from which the <c>svn log</c> command will be run.
  /// </summary>
  /// <value>The repository.</value>
  [ReflectorProperty("url", Required = true)]
  public string Url
    return _url;
    _url = value;

  /// <summary>
  /// Gets or sets the Subversion client executable.
  /// </summary>
  /// <value>The path to the executable.</value>
  /// <remarks>
  /// If the value is not supplied, the task will expect to find <c>svn.exe</c> in the <c>PATH</c> environment variable.
  /// </remarks>
  [ReflectorProperty("executable", Required=false)]
  public string Executable
    return executable;
    executable = value;

  /// <summary>
  /// Gets or sets an optional prefix for the build label.
  /// </summary>
  /// <value>A string to prefix the version number with.</value>
  [ReflectorProperty("prefix", Required=false)]
  public string Prefix
    return prefix; 
    prefix = value;

  /// <summary>
  /// Gets or sets the username to access SVN repository.
  /// </summary>
  /// <value>The repository.</value>
  [ReflectorProperty("username", Required = false)]
  public string Username
    return username;
    username = value;

  /// <summary>
  /// Gets or sets the password to access SVN repository.
  /// </summary>
  /// <value>The repository.</value>
  [ReflectorProperty("password", Required = false)]
  public string Password
    return password;
    password = value;


  #region Private methods

  /// <summary>
  /// Parses the version.
  /// </summary>
  /// <param name="revision">The revision.</param>
  /// <param name="resultFromLastBuild">The result from last build.</param>
  private Version ParseVersion(int revision, IIntegrationResult resultFromLastBuild)
    string label = resultFromLastBuild.LastSuccessfulIntegrationLabel;
    if (prefix.Length > 0)
     label = label.Replace(prefix, String.Empty).TrimStart('_');
    return new Version(label);
   catch (SystemException)
    return new Version(major, minor, revision, 0);

  /// <summary>
  /// Gets the latest Subversion revision by checking the last log entry.
  /// </summary>
  private int GetRevision()
   // Set up the command-line arguments required
   ProcessArgumentBuilder argBuilder = new ProcessArgumentBuilder();
   argBuilder.AppendArgument("--limit 1");
   if (Username != null && Username.Length > 0 && Password != null && Password.Length > 0)

   // Run the svn log command and capture the results
   ProcessResult result = RunProcess(argBuilder);
   Log.Debug("Received XML : " + result.StandardOutput);

   // Load the results into an XML document
   XmlDocument xml = new XmlDocument();

   // Retrieve the revision number from the XML
   XmlNode node = xml.SelectSingleNode(RevisionXPath);
   return Convert.ToInt32(node.InnerText);

  /// <summary>
  /// Appends the arguments required to authenticate against Subversion.
  /// </summary>
  /// <param name="buffer"><The argument builder./param>
  private void AppendCommonSwitches(ProcessArgumentBuilder buffer)
   buffer.AddArgument("--username", Username);
   buffer.AddArgument("--password", Password);

  /// <summary>
  /// Runs the Subversion process using the specified arguments.
  /// </summary>
  /// <param name="arguments">The Subversion client arguments.</param>
  /// <returns>The results of running the process, including captured output.</returns>
  private ProcessResult RunProcess(ProcessArgumentBuilder arguments)
   ProcessInfo info = new ProcessInfo(executable, arguments.ToString(), null);
   Log.Debug("Running Subversion with arguments : " + info.Arguments);

   ProcessExecutor executor = new ProcessExecutor();
   ProcessResult result = executor.Execute(info);
   return result;


Comparing to CCNET, CruiseControl does not provide very powerful preprocessor and template feature. There is no syntax to define XML fragment (except using DTD). The main config file, config.xml, cannot be automatically reloaded if any configuration changed.

<?xml version="1.0" encoding="utf-8" ?>
<!--# Always deploy ccnet.config with following files under ${env.CCDIR}
      also place cruisecontrol.jar under "${env.CCDIR}\lib" to overwrite
      original one for a customized new plugin: <ZSVNLabeller />
  <property file="" />
  <property environment="env" toupper="true" />
  <property name="url_cruisecontrol" value="${url_cchost}/cruisecontrol" />
  <property name="url_buildresults" value="${url_cruisecontrol}/buildresults" />
  <property name="url_ccdashboard" value="${url_cchost}/dashboard" />
  <property name="url_ccdoc" value="${url_cchost}/documentation" />

  <include.projects file="prj_MyProject.xml" />


As in above sample of config.xml, property definition is either by <property name="var" value="text" /> element or an external file (e.g.

# Filename:
#    Usage: called by cruisecontrol element, i.e.:
#           <property file="" />
#   Syntax: defined by the class java.util.Properties, with the same rules
#           about how non-ISO8859-1 characters must be escaped.

### default value predefinitions

### dir/path predefinitions

### svn settings predefinitions

### user id predefinitions

### url predefinitions

Certainly, a project file (e.g. prj_MyProject.xml) can be included in config.xml so that the configuration is well organized by each individual config file. Here only provides a project template file that a real project config (e.g. prj_MyProject.xml) will be based on.

<?xml version="1.0" encoding="utf-8" ?>
  For each project, use following steps to create a project file from this template by
  copying this file to a new project file, in convention of "prj_$[project_name].xml":
  (1) replace "$[project_name]" with a project name
  (2) replace any place holder definition, like in format of $[place_holder], in property definitions
  (3) optionally use ${def_project_buildTime} for ${project_buildTime}
  (4) optionally add more ${project_buildTarget[n]} properties and publishers
  (5) choose one of the build methods in <project><schedule></schedule></project> block
  (6) replace "\\" to "/" on Linux system
  (7) replace ${dir_svn_target} with ${smb_svn_target} on a Linux build system
  (8) define properties ${eid_*} for build notification; ${uid_builder} has been notified on success
  (9) refer to any property definitions in
  <project name="$[project_name]">
    <property name="project_name"        value="${}" />
    <property name="project_alias"       value="$[project_alias]" />
    <property name="project_category"    value="$[project_category]" />
    <property name="project_root"        value="$[project_root]" />
    <property name="project_path"        value="$[project_path]" />
    <property name="project_branch"      value="$[project_branch]" />
    <property name="project_svnServer"   value="$[project_svnServer]" />
    <property name="project_svnPath"     value="svn://${project_svnServer}/${project_root}${project_path}/${project_branch}" />
    <property name="project_source"      value="${env.CCDIR}\\projects\\${}" />
    <property name="project_buildTarget" value="$[project_buildTarget]" />
    <property name="project_buildTime"   value="${def_project_buildTime}" />
    <property name="project_buildTime"   value="$[project_buildTime]" />
    <property name="project_checkTime"   value="30" />
    <property name="url_cruisecontrol"   value="${url_cruisecontrol}" />
    <property name="eid_failure"         value="builder" />
    <property name="eid_success"         value="builder" />
    <property name="eid_always"          value="developer_alias" />

    <plugin name="svn" classname="net.sourceforge.cruisecontrol.sourcecontrols.SVN" />
    <plugin name="ZSVNLabeller" classname="net.sourceforge.cruisecontrol.labelincrementers.ZSVNLabeller" />

    <ZSVNLabeller separator="r" labelprefix="r" workingcopypath="${project_source}"
      <currentbuildstatuslistener file="logs/${}/status.txt"/>
      <antbootstrapper anthome="apache-ant-1.7.0" 
                       target="clean" />
     <execbootstrapper command=""
                       args="" workingdir="projects/${}"
                       errorstr="" showProgress=""
      <svnbootstrapper localWorkingCopy="${project_source}"

    <modificationset quietperiod="60">
      <!--# <filesystem/> triggers a build if any file in ${} project is touched
      <filesystem folder="${project_source}" includedirectories="false" />
      <!--# <svn/> sets property ${svnrevision}
      <svn localWorkingCopy="${project_source}"

    <schedule interval="{project_checkTime}">
      <!--#<ant />
      <ant anthome="apache-ant-1.7.0" buildfile="projects/${}/build.xml"/>
      <exec command=".\\build.cmd"
            args='"${project_source}"' workingdir="${project_source}"
            errorstr="Build Failed" showProgress="true"

      <!--# merge from log files with specified pattern from specified dir
      <merge dir="${project_source}\\log" pattern="*.log" />
      <deleteartifacts every="30" unit="DAY" />
      <delete every="30" unit="DAY" />

      <htmlemail buildresultsurl="${url_cruisecontrol}/buildresults/${project_name}"
                 defaultsuffix=".com" mailhost="" mailport="25" usessl="false"
                 returnaddress="" returnname="Builder"
        <success address="${uid_builder}" /><!--send to builder success notification-->
        <success address="${eid_success}" />
        <failure address="${eid_failure}" />
        <always  address="${eid_always}"  />

        <antpublisher anthome="apache-ant-1.7.0"
          <property name="publish_source" value="${project_source}\\${project_buildTarget}" />
          <property name="publish_target" value="${dir_svn_target}\\${project_alias}" />
        <antpublisher anthome="apache-ant-1.7.0"
          <property name="publish_source" value="${project_source}\\${project_buildTarget}" />
          <property name="publish_target" value="${dir_svn_target}\\${project_alias}" />



The template cannot be used as nicely as in CCNET. But it gives a start for most projects. Please refer to usage comments at beginning of the template. Also remember since CruiseControl is running on both Windows and Linux systems, backslash or forward-slash need to be carefully used wherever a path is typed.

One of the difference in CruiseControl than CCNET is the sequence of continuous integration cycle. In CCNET, the <sourcecontrol /> compares last build state with repository server, then checkout (for the first time of check) or update source code on local working directory before starting build tasks. But in CruiseControl, the bootstrapper is always called at the beginning to update local working directory from server before using <modificationset /> to detect if tasks in <schedule /> need to be executed.

Such difference implies that the local working directory and source code in CruiseControl project must be manually checked out from the repository (such as `svn co`) at the time when the project is setup, which is not necessary in CCNET – where the local working directory can be created automatically if it does not exist. This also explains why LocalWorkingCopy (rather than RepositoryLocation) property should be used in <svn /> source control under <modificationset /> to detect new commit for a CruiseControl project.

Note: There could be a chance that local working copy has not been updated yet when a new change is committed on repository server after bootstrapper but before modificationset. The race condition will end up building old source against a newer revision label.

Modification of subversion in CruiseControl is parsed from `svn log -r` by checking between last build time and current time. If useLocalRevision property is used in <svn /> source control, the local revision number will be in place of current time.

At the end of the template, artifacts publishing is implemented by the following include file.

<project name="antpublisher_copy" default="publish">
    <target name="publish">
        <echo>Copying ${publish_source} to ${publish_target} ...</echo>
        <copy todir="${publish_target}"><fileset dir="${publish_source}" /></copy>
    <target name="publish_dir">
        <echo>Copying ${publish_source} to ${publish_target}-${label} ...</echo>
        <copy todir="${publish_target}-${label}"><fileset dir="${publish_source}" /></copy>
    <target name="publish_file">
        <echo>Copying ${publish_source} to ${publish_target}-${label} ...</echo>
        <copy todir="${publish_target}-${label}" file="${publish_source}"></copy>
    <target name="publish_artifacts">
        <echo>Copying ${publish_source_dir} to ${publish_target} ...</echo>
        <copy todir="${publish_target}">
   <fileset dir="${publish_source_dir}">
    <include name="${publish_source_files}" />

The Java source code of “ZSVNLabeller” plugin (based on SVNLabelIncrementer, implements LabelIncrementer) is attached as below. The file “” should be place under source code folder “net\sourceforge\cruisecontrol\labelincrementers“. After rebuilt, copy “cruisecontrol.jar” to ${env.CCDIR}, where CruiseControl installed.

package net.sourceforge.cruisecontrol.labelincrementers;


import net.sourceforge.cruisecontrol.LabelIncrementer;

import org.apache.log4j.Logger;
import org.jdom.Element;

 * This class provides a label incrementation based on svn revision numbers.
 * This class expects the label format to be "x&lt;sep&gt;y[&lt;sep&gt;z]",
 * where x is any String and y is an integer and &lt;sep&gt; a separator, the
 * last part z, is optional, and gets generated and later incremented in case a
 * build is forced. The default separator is "." and can be modified using
 * {@link #setSeparator}.
 * @author Ketan Padegaonkar &lt; KetanPadegaonkar gmail &gt;

/// UPDATE: return revisionNumber if separator is as same as prefix - Boathill

public class ZSVNLabeller implements LabelIncrementer {
    private static final Logger LOG = Logger.getLogger(ZSVNLabeller.class);

    private String workingCopyPath = ".";

    private String labelPrefix = "svn";

    private String separator = ".";

    public boolean isPreBuildIncrementer() {
        return true;

    public String incrementLabel(String oldLabel, Element buildLog) {
        String revisionNumber = "";
        String result = oldLabel;
        try {
            revisionNumber = getSvnRevision();

            if (getSeparator().equals(getLabelPrefix())) {
                return labelPrefix + revisionNumber; // return svn revison only
            if (revisionNumber == null || revisionNumber.equals("")) {
                return labelPrefix;
            result = labelPrefix + getSeparator() + revisionNumber;

            if (oldLabel.indexOf(result) > -1) {
                int lastSeparator = oldLabel.lastIndexOf(getSeparator());
                int firstSeparator = oldLabel.indexOf(getSeparator());
                int lastPart = 1;
                if (lastSeparator != firstSeparator) {
                    String suffix = oldLabel.substring(lastSeparator + 1);
                    lastPart = Integer.parseInt(suffix) + 1;
                result += getSeparator() + lastPart;
            LOG.debug("Incrementing label from " + oldLabel + " to " + result);
        } catch (IOException e) {
            LOG.error("could not execute svn binary", e);
        } catch (NumberFormatException e) {
            LOG.error("could not increment label. Old label was " + oldLabel + ". svn revision was " + revisionNumber,

        return result;

    protected String getSvnRevision() throws IOException {
        String rev;
        Process p = null;
        try {
            p = Runtime.getRuntime().exec(new String[]{"svnversion", workingCopyPath});
            BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
            rev = stdInput.readLine();
        } finally {
            if (p != null) {
        LOG.debug("SVN revision is: " + rev);
        return rev;

    public boolean isValidLabel(String label) {
        // we don't mind what the previous label is,
        // when the next label is built, then parsing is performed to add / increment a suffix.
        return true;

    public void setWorkingCopyPath(String path) {
        LOG.debug("Working Path is: " + path);
        workingCopyPath = path;

    public String getLabelPrefix() {
        return this.labelPrefix;

    public void setLabelPrefix(String labelPrefix) {
        this.labelPrefix = labelPrefix;

    public String getDefaultLabel() {
        return getLabelPrefix() + getSeparator() + "0";

    public String getSeparator() {
        return this.separator;

    public void setSeparator(String separator) {
        this.separator = separator;


Some other Continuous Integration products, e.g. Cruise and Hudson, have much nicer web interface, while CruiseControl.NET and CruiseControl provides better flexibility and can be greatly customized. However, the flexibility sometimes means difficulty. For example, CruiseControl has three web sites – dashboard (:8080), project cruisecontrol (:8000), and JMS console – but not be seen on one page; CruiseControl supports CCNET CCTray but could not integrate with CCNET projects or dashboard (even if both developed by ThoughtWorks).

The build publisher supports using build label in both CCNET (by <labeller />) and CruiseControl (${label} in ant config). And in CCNET, the build publisher has to copy all contents in a specified source to another location although ant or nant can be used to customize such task. CruiseControl web interfaces do have a little more advanced features than CCNET. As an instance, the build target files (artifacts) can be published on CruiseControl dashboard so that can be downloaded. But the artifact in CCNET is just a local folder not accessible from the web.

On the other hand, CruiseControl does not display the runtime log on web interfaces. The build log can only be reviewed after the build is done. In CCNET dashboard, this is provided by a server log link. Although the server log in CCNET is not automatically updated (as nicely as a real time console display in Hudson), it at least gives user some hint before knowing the build succeeded or failed. Having better integration with Windows, CCNET can be run in either command line or service mode. For CruiseControl, you have to write a /etc/init.d/cruisecontrol.

Since CruiseControl.NET derived from CruiseControl, both work the same way and the cofiguration shares similarity. As open source projects, it is convenient to develop or modify plugin to suite need during implementation. CruiseControl is cross-platform by Java technology. CCNET has improved on web integration and preprocessor configuration so that project file can be well structured via nodeset expansion template.

Note: Source code samples are formatted by SyntaxHighlighter.

Written by Boathill

2009-07-16 at 09:00

22 Responses

Subscribe to comments with RSS.

  1. […] The busiest day of the year was September 26th with 648 views. The most popular post that day was CCNet vs. CruiseControl. […]

  2. Hello there, I found your blog via Google whilst looking for a similar topic, your website
    got here up, it seems to be good. I’ve bookmarked it in my google bookmarks.


    2013-05-06 at 07:50

  3. Oh my goodness! Impressive article dude! Thank you so much,
    However I am experiencing troubles with your RSS. I don’t understand the reason why I am unable to subscribe to it. Is there anybody getting the same RSS issues? Anyone who knows the answer will you kindly respond? Thanx!!

    e cigarette

    2013-04-18 at 18:04

  4. Useful. I agree.

    Abused Men

    2013-01-08 at 15:24

  5. hi I was fortunate to come cross your website in yahoo
    your Topics is wonderful
    I learn much in your blog really thank your very much
    btw the theme of you blog is really fabulous
    where can find it


    2010-11-22 at 23:59

  6. I am not new to blogging and really appreciate your blog. There is much original content that peaks my interest. I am going to bookmark your site and keep checking you out.

    Directoare web

    2010-11-16 at 03:14

  7. Thanks for the article. I thought it was interesting.

    Austin C

    2010-11-12 at 05:04

  8. Love it. Great job of putting this work together.


    2010-11-11 at 07:24

  9. Hello there,

    This is a question for the webmaster/admin here at

    May I use part of the information from this blog post above if I provide a backlink back to this site?


    2010-11-10 at 22:55

    • Hi Peter, your comment post was sent to Spam folder. I cannot really read your site — are you working with CruiseControl or anything related?


      2010-11-22 at 14:11

  10. A Quite easy to follow input . Every time i read your website i read a different perspective . Furthermore , as a noob developer, i need to say that the structure of your website is amazing . Could you post some information regarding the theme ? . I find it hard to choose among all these themes and widgets.
    Thanks .


    2010-10-31 at 06:27

    • Hey Isno, this site is using “The Journalist v1.9 by Lucian E. Marin” ( The blog is a free service from One of the disadvantage is that the theme template is not accessible/editable (as, although does provide a lot of other features.


      2010-10-31 at 07:35

  11. Hey – wonderful blog site, just looking around some weblogs, seems a pretty wonderful platform you are using. I’m presently using Drupal for a few of my sites but looking to modify one of them over to a platform similar to yours as a trial run. Anything in particular you would advise about it? My best wishes, Tommye Simas.

    Tommye Simas

    2010-10-31 at 03:12

  12. I have been looking forever to find something like this! Great trick and I must say, it works great.

    make beats online

    2010-10-30 at 07:43

  13. Good work, I am a big believer in leaving comments on blogs to help the blog writers know that they’ve added something useful to the internet!


    2010-10-28 at 04:17

  14. Your Word Press design looks awesome!!

    Wahrsagen Online

    2010-03-08 at 03:51

  15. Thanks for an idea, you sparked at idea from a angle I hadn’t given thoguht to before . Now lets see if I can do something with it.

  16. I was just doing some web browsing on my Nokia Phone during my spare time at work , and I happened across something I thought was intriguing. It linked over to your website so I clicked over. I can’t really find the relevance between your site and the one I came from, but your site good anyway.

    San Diego short sale

    2010-03-05 at 14:44

  17. For some reason only half of the post is being displayed, could it be my browser or the site?

  18. As a Newbie, I’m often searching on the net for articles that can assist me. Thank you

    Marcellus Fitzhugh

    2010-02-20 at 15:40

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your 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

%d bloggers like this: