Integrating CC.NET with NAnt and Subversion on Windows - No Fluff Just Stuff

Integrating CC.NET with NAnt and Subversion on Windows

Posted by: Paul Duvall on May 1, 2006

You may have heard of Continuous Integration (CI) for .NET, but perhaps thought it would take too long to install and configure the tools. By integrating the CC.NET, NAnt, and Subversion tools, you can quickly create a robust CI solution. In this entry, I walk you through the setup and configuration of these tools, step by step.

There are many ways to define CI, but just think of it as a process of integrating your software when a change is applied to your SCM repository. This may include compiling, inspecting, testing, deploying, and generating feedback.

Prerequisites
You need to install and configure IIS and have access to a Subversion repository. If you’d like a Subversion project to use for this example, use http://www.qualitylabs.org/svn/ndbunit/. Note: You will need an account established at qualitylabs.org.

Step 1 - Download and install tools
Subversion is the SCM tool used to manage your source code. Extract the Win32 version of the Subversion zip (svn-win32…) file to a designated directory
NAnt is the build scripting tool to build your software. Extract the NAnt zip file to a designated directory
CC.NET is the CI tool to run your build script whenever a change occurs in your SCM. Save and run the installation .exe file. CC.NET should be installed on a separate machine than the developer machines. However, for the purposes of this example, you will be installing CC.NET on the same machine.


Step 2 - Configure Subversion
Create a Windows environment variable called SVN_HOME. The value should equal the location of the Subversion installation directory from step 1. Add %SVN_HOME%\bin; to the System PATH environment variable.

  • Open a command window and type svn. You should receive a message like: Type ’svn help’ for usage.


  • Step 3 - Configure NAnt

  • Create a Windows environment variable called NANT_HOME. The value should equal the location of the NAnt installation directory from step 1.
  • Add %NANT_HOME%\bin; to the System PATH environment variable.
  • Open a command window and type nant. You should receive a message like: BUILD FAILED. Could not find a ‘*.build’ file…


  • Step 4 - Create NAnt build file
    Create the following and save as default.build.

    <?xml version="1.0"?>
    <project name="HelloWorld" default="build">
      <target name="init" depends="clean" />
      <target name="clean" />
      <target name="checkout"/>
      <target name="compile"/>
      <target name="deploy"/>
      <target name="test"/>
      <target name="inspect"/>
      <target name="build" depends="init, checkout">
        <call target="compile" />
        <call target="inspect" />
        <call target="test" />
        <call target="deploy" />
      </target>
    </project>
  • Open a command window again and type nant in the same directory where you placed the default.build file.
    After a short time, BUILD SUCCEEDED should be displayed.


  • Step 5 - Configure CC.NET
    Go to the directory where you installed CC.NET in Step 1. From here, go to the server subdirectory. In this directory there is a file called ccnet.config. Open this file and add the following:

    <cruisecontrol>
      <project name="HelloWorld">
      <schedule type="schedule" timeout="60000"/>
      <modificationDelay>10000</modificationDelay>
      <sourcecontrol type="svn">
        <trunkUrl>http://www.qualitylabs.org/svn/ndbunit/</trunkUrl>
        <executable>C:/dev/testearly/svn-win32-1.3.1/bin/svn.exe</executable>
        <username>george.washington</username>
        <password>M@rtha</password>
        <workingDirectory></workingDirectory>
        <artifactDirectory></artifactDirectory>
        <autoGetSource>true</autoGetSource>
      </sourcecontrol>
      <build type="nant">
        <executable>C:/dev/testearly/nant-0.85-rc3/bin/nant.exe</executable>
        <baseDirectory>C:/dev/testearly/</baseDirectory>
        <buildFile>default.build</buildFile>
        <targetList>
          <target>build</target>
        </targetList>
        <buildTimeout>300000</buildTimeout>
      </build>
      <publishers>
      <xmllogger>
        <logDir>.websitelog</logDir>
      </xmllogger>
      </publishers>
      </project>
    </cruisecontrol>

    Update the trunkUrl attribute to the location of your Subversion server and project. Open a web browser and type:
    http://localhost/ccnet/
    The following should be displayed:
    CCNET Dashboard

    Troubleshooting
    You may get tripped up with a few problems along the way. Here’s a list of some of some of the issues along with some troubleshooting techniques:

  • PROBLEM: In attempting to access http://localhost/ccnet/, the CC.NET web dashboard page does not display
  • SOLUTION: Ensure that ASP.NET has been registered. It is usually located at C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322 (or something similar) From here, run aspnet_regiis.exe /i. Also, ensure that the CruiseControl.NET service is installed and running by viewing the Services applet. Finally, ensure that you have installed and configured IIS (you may need to add a virtual directory for CC.NET if you install IIS after installing CC.NET.
  • PROBLEM: When you type nant and/or svn on the command line, you get a message like “‘nant/svn’ is not recognized as an internal or external command…”
  • SOLUTION: Ensure that the locations of the NANT_HOME and/or SVN_HOME environment variables reside on your computer. Also ensure that the % and ; symbols are used properly. Lastly, verify that the svn-win32 version has been installed on your machine, so that the svn.exe can be located.


  • Conclusion
    Of course, this is a very basic solution of integrating these tools. You’ll want to expand the NAnt build script to provide meaningful activities such as running automated tests and inspections and deploying the software. If you need to use a different SCM, you can simply change the source control configuration block in ccnet.config. By integrating your software upon any material source code change, you can better ensure that you will have working software by running through consistent, repeatable steps that compile, test, inspect, and deploy your software (into a development/testing environment). Integrate early. Integrate often.

    Paul Duvall

    About Paul Duvall

    Paul M. Duvall is the CEO of Stelligent, a consulting firm that helps clients create production-ready software every day. He has worked in virtually every role on software projects: developer, project manager, architect and tester. He's been a featured speaker at many leading software conferences. He is the principal author of Continuous Integration: Improving Software Quality and Reducing Risk (Addison-Wesley, 2007; Jolt 2008 Award Winner). He contributed to the UML 2 Toolkit (Wiley, 2003), authors a series for IBM developerWorks called Automation for the people and authored a chapter in the No Fluff Just Stuff Anthology: The 2007 Edition (Pragmatic Programmers, 2007). He is passionate about automating software development and release processes. He actively blogs on IntegrateButton.com

    Why Attend the NFJS Tour?

    • » Cutting-Edge Technologies
    • » Agile Practices
    • » Peer Exchange

    Current Topics:

    • Languages on the JVM: Scala, Groovy, Clojure
    • Enterprise Java
    • Core Java, Java 8
    • Agility
    • Testing: Geb, Spock, Easyb
    • REST
    • NoSQL: MongoDB, Cassandra
    • Hadoop
    • Spring 4
    • Cloud
    • Automation Tools: Gradle, Git, Jenkins, Sonar
    • HTML5, CSS3, AngularJS, jQuery, Usability
    • Mobile Apps - iPhone and Android
    • More...
    Learn More »