Configure a CruiseControl Project

From Ssdlpedia
Jump to: navigation, search

Contents

What is CruiseControl?

CruiseControl is continuous integration server. It constantly monitors the source control system of your project. When it detects that a source file was changed/added it checks out the latest version of the project, compiles it and runs its unit tests. It then publishes the results of the build in various ways (web page, e-mail, rss).

A Step-by-Step Example

Assumptions

  • Project name: p111
  • URL of the project (in the SVN repository): https://ssdl-linux/svn/my-repository/trunk/p111 (the project is already checked-in).
  • The project contains a lib/ directory with JUnit's jar file (e.g.: junit-4.4.jar)
  • Your project's main test suite class is: my.project.my.package.MainTestClass.
  • Your e-mail address is: myself@my.mail.com

Directories

  • CruiseControl working directory: $CCWORKING (currently: /home/assistants/imaman/cc-working)
  • CruiseControl installation directory: $CCINSTALL (currently: /home/assistants/imaman/cc)

Projects are defined in the working directory. There's no need to touch the installation directory.


Steps

  • Create an ant build file (build.xml) for your project (Ant Build File Example).
  • Define ant targets in the build file (build.xml)
<target name="test" depends="compile">
  <mkdir dir="junit-results"/>
    <junit dir="${basedir}" fork="on" haltonfailure="yes" printsummary="on">
      <classpath>
        <pathelement location="bin"/>
        <pathelement location="lib/junit-4.4.jar"/>
      </classpath>
      <formatter type="brief" usefile="false"/>
      <formatter type="xml" />
      <test name="my.project.my.package.MainTestClass" todir="junit-results" fork="yes"/>
    </junit>
</target>
 
<target name="jar" depends="test">
  <delete dir="artifacts" quiet="true" />
  <mkdir dir="artifacts"/>
  <jar jarfile="output/p111.jar" basedir="bin"/>
</target>
  • Create a directories
cd $CCWORKING
mkdir logs/p111
mkdir artifacts/p111
  • Checkout the latest version of your project from the SVN
cd $CCWORKING/checkout/
svn co https://ssdl-linux/svn/my-repository/trunk/p111
  • Create a delegating ant script: This is a short ant file that (a) updates your project and then (b) runs the tests by invoking your project's own build.xml file. By convention it is called build-p111.xml and placed in $CCWORKING. Here is how it looks like:
<project name="build-p111" default="build" basedir="checkout">
  <taskdef name="svn" classname="org.tigris.subversion.svnant.SvnTask" />
 
  <target name="build">
    <svn><update dir="p111"/></svn>
    <ant antfile="build.xml" dir="p111" target="jar"/>
  </target>
 
</project>
  • Test the delegating script
cd $CCWORKING
ant -f build-p111.xml
  • Add a <project> element to $CCWORKING/config.xml. This sets various properties related to your project (e.g.: e-mail notification address). Note that it refers to files in the $CCINSTALL directory, so you need to set these paths correctly. A detailed description of this xml file can be found here
<project name="p111" buildafterfailed="false">
 
    <listeners>
      <currentbuildstatuslistener file="logs/p111/status.txt" />
    </listeners>
 
    <bootstrappers />
 
    <modificationset quietperiod="10">
      <svn localworkingcopy="checkout/p111" />
    </modificationset>
 
    <schedule interval="60">
      <ant anthome="$CCINSTALL/apache-ant-1.7.0" buildfile="build-p111.xml" target="build" uselogger="true" usedebug="false" />
    </schedule>
 
    <log logdir="logs/p111">
      <merge dir="checkout/p111/junit-results/" />
    </log>
 
    <publishers>
 
      <htmlemail mailhost="localhost"
          returnaddress="cc@ssdl-linux.cs.technion.ac.il"
          subjectprefix="[CuiseControl]"
          skipusers="true"
          css="$CCINSTALL/webapps/cruisecontrol/css/cruisecontrol.css"
          xsldir="$CCINSTALL/webapps/cruisecontrol/xsl" logdir="logs/p111">
        <always address="myself@my.mail.com" />
      </htmlemail>
 
      <onsuccess>
        <artifactspublisher
            file="checkout/p111/output/p111.jar"
            dest="artifacts/p111"/>
      </onsuccess>
 
    </publishers>
 
  </project>

That's it, you're done. You can now see your project by pointing your browser to: http://ssdl-linux:8080

Personal tools