Tuesday, May 19, 2009

An easier way to manage CruiseControl.Net projects

In a much older post I showed a quick way to remove duplication in a CruiseControl.Net (CCNet) config file. Since then, CCNet has added a Configuration Preprocessor to not only simplify this process, but also split the ccnet.config into multiple files - one per project.

To start with, we need to modify ccnet.config to specify the correct xml namespace:

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

Now we move an existing project from ccnet.config into a separate file. Note this new file starts with 'project' as the root node, and must also have the correct xml namespace.

<project xmlns:cb="urn:ccnet.config.builder">
    <name>My Test Project</name>
    <triggers>
        <intervalTrigger seconds="60" />
    </triggers>
    <sourcecontrol type="svn">
        <executable>svn.exe</executable>
        <trunkUrl>svn://MySourceServer/myAppPath</trunkUrl>
        <workingDirectory>C:\CCNetProjects\MyTestProject</workingDirectory>
        <username>svnUser</username>
        <password>svnPassword</password>
        <autoGetSource>true</autoGetSource>
    </sourcecontrol>
    <tasks>
        <msbuild>
            <logger>c:\ThoughtWorks.CruiseControl.MSBuild.dll</logger>
            <projectFile>MyTestProject.sln</projectFile>
            <buildArgs>/noconsolelogger</buildArgs>
            <targets>Build</targets>
            <workingDirectory>D:\CCNetProjects\MyTestProject</workingDirectory>
        </msbuild>
    </tasks>
    <publishers>
        <statistics/>
        <xmllogger/>
        <artifactcleanup cleanUpMethod="KeepLastXBuilds" cleanUpValue="25" />
    </publishers>
</project>

In the main ccnet.config, our project information can be replaced with an include that points to our new project config:

<cb:include href="C:\MyTestApp.ccnet.config" />

Instead of one massive config file, we now split it by project. This makes adding, removing, or modifying projects much easier. As an added bonus, CCNet monitors the project-specific config files and reloads them if anything changes.

I mentioned that we can also use the preprocessor to reduce duplication. In the project config above, note the Subversion username and password nodes:

<username>svnUser</username>
<password>svnPassword</password>

If we define these values in each individual config, changing them requires a find/replace across multiple files. What we want to do is define them once in the main ccnet.config and then include them in our project configs. To do this, we start by adding the following to ccnet.config

<cb:define name="svnCredentials">
    <username>svnUser</username>
    <password>svnPasswrod</password>
</cb:define>

In our project config we can replace the two credential nodes with a single reference to 'svnCredentials'. If we ever change the account our buildserver uses to pull code, we only need to change the credentials once.

<sourcecontrol type="svn">
    <executable>svn.exe</executable>
    <trunkUrl>svn://MySourceServer/myAppPath</trunkUrl>
    <workingDirectory>C:\CCNetProjects\MyTestProject</workingDirectory>
    <cb:svnCredentials/>
    <autoGetSource>true</autoGetSource>
</sourcecontrol>

1 comment:

Note: Only a member of this blog may post a comment.