KB: CruiseControl on Ubuntu

Installation and configuration guide for CruiseControl on Ubuntu Linux.

Contents

Install

1. Download CruiseControl from here.
2. Create a user for CruiseControl:

adduser cruisecontrol

3. Extract the source to /opt:

unzip cruisecontrol-bin-2.7.1.zip

4. Make the user created above owner of CruiseControl:

chown -R cruisecontrol:cruisecontrol cruisecontrol

5. Verify that the Subversion client is installed on the machine running CruiseControl.

Configure

1. If you are going to use the svnant libraries, extract svnant, svnClientAdapter and svnjavahl jar files to INSTALL_DIR/apache-ant-1.7.0/lib.

2. In the INSTALL_DIR directory, create a properties file for any custom settings needed by your delegating build scripts:


# -------------------------------------------
# zunisoft.properties
# Custom properties for CC ant build files.
# -------------------------------------------
svnant.version=1.0.0
# -------------------------------------------
# Custom Ant tasks
# -------------------------------------------
lib.dir=apache-ant-1.7.0/lib
svnant.jar=${lib.dir}/svnant.jar
svnClientAdapter.jar=${lib.dir}/svnClientAdapter.jar
svnjavahl.jar=${lib.dir}/svnjavahl.jar

3. If everything is running swimmingly and because I get lazy and don’t want to mess with managing the cruisecontrol.log file:

ln -s /dev/null cruisecontrol.log

Add Your Project

1. In the INSTALL_DIR/projects directory, check out a copy of your project:

svn co file://localhost/var/svn/openeprs/trunk/openeprs-ant

2. In the INSTALL_DIR directory, create a delegating build script named build-openeprs-ant.xml:


  <project basedir="projects/openeprs-ant" default="build" name="build-openeprs-ant">
    <property file="../../zunisoft.properties">
    <path id="project.classpath">
      <pathelement location="${svnjavahl.jar}">
      <pathelement location="${svnant.jar}">
      <pathelement location="${svnClientAdapter.jar}">
    </path>
    <taskdef classpathref="project.classpath" resource="svntask.properties">
    <target name="build">
      <svn>
        <update dir=".">
      </svn>
      <ant antfile="build.xml" target="clean">
      <ant antfile="build.xml" target="jar">
      <ant antfile="build.xml" target="test">
    </target>
  </project>

3. Edit INSTALL_DIR/config.xml to add your project so CC can build it. This is not an optimal example but, it does show how to configure one build to depend on another:


 <cruisecontrol>
  <project buildafterfailed="false" name="openeprs-libs">
      <listeners>
        <currentbuildstatuslistener file="logs/${project.name}/buildstatus.txt">
      </listeners>
      <bootstrappers>
        <svnbootstrapper localworkingcopy="projects/${project.name}">
      </bootstrappers>
      <modificationset quietperiod="10">
        <svn localworkingcopy="projects/${project.name}">
      </modificationset>
      <schedule interval="60">
        <ant
             anthome="apache-ant-1.7.0"
             buildfile="build-${project.name}.xml"
             target="build"
             uselogger="true"
             usedebug="false"/>
      </schedule>
      <log dir="logs/${project.name}">
      <publishers>
        <onsuccess>
          <artifactspublisher dest="artifacts/${project.name}" file="projects/${project.name}/dist/${project.name}.jar">
        </onsuccess>
        <email
               mailhost="127.0.0.1"
               username="XXXXXX"
               password="XXXXXX"
               returnaddress="no-reply@zunisoft.com"
               buildresultsurl="http://cc.zunisoft.com/dashboard/build/detail/${project.name}"
               skipusers="true" spamwhilebroken="true">
          <failure address="keith.davis@zunisoft.com">
      </email>
    </publishers>
  </project>
  <project buildafterfailed="false" name="openeprs-ant">
    <listeners>
      <currentbuildstatuslistener file="logs/${project.name}/buildstatus.txt">
    </listeners>
    <bootstrappers>
      <svnbootstrapper localworkingcopy="projects/${project.name}">
    </bootstrappers>
    <modificationset quietperiod="10">
      <buildstatus logdir="logs/openeprs-libs">
      <svn localworkingcopy="projects/${project.name}">
    </modificationset>
    <schedule interval="60">
      <ant
           anthome="apache-ant-1.7.0"
           buildfile="build-${project.name}.xml"
           target="build"
           uselogger="true"
           usedebug="false"/>
    </schedule>
    <log dir="logs/${project.name}">
      <merge dir="projects/${project.name}/build/test/results/">
    </log>
    <publishers>
      <onsuccess>
        <artifactspublisher dest="artifacts/${project.name}" file="projects/${project.name}/dist/${project.name}.jar">
        <artifactspublisher dest="artifacts/${project.name}/JUnit" dir="projects/${project.name}/build/test/results/html/">
      </onsuccess>
      <email
             mailhost="127.0.0.1"
             username="XXXXXX"
             password="XXXXXX"
             returnaddress="no-reply@zunisoft.com"
             buildresultsurl="http://cc.zunisoft.com/dashboard/build/detail/${project.name}"
             skipusers="true" spamwhilebroken="true">
        <failure address="keith.davis@zunisoft.com">
      </email>
    </publishers>
  </project>
</cruisecontrol>

Startup Script

If you want to start CC at boot time:


#! /bin/sh
#
# Keith Davis - 10/06/2007
# ADD: update-rc.d cruisecontrol.sh defaults
# REMOVE: update-rc.d cruisecontrol.sh remove
# /etc/init.d/cruisecontrol.sh: start and stop Cruise Control
test -f /lib/lsb/init-functions || exit 1
. /lib/lsb/init-functions

####################
# USER CONFIGURATION
#
# Fill in these values for your Cruise Control setup
# What user will Cruise Control run as?  The user will need
# permission to write and modify files
# in the next entries.
CC_USER=cruisecontrol
# Where is the CC startup script located?
CC_INSTALL_DIR=
# In what directory is the config.xml file located for CC?
# default: CC_WORK_DIR=$CC_INSTALL_DIR
CC_WORK_DIR=$CC_INSTALL_DIR
# Where will the cruisecontrol.log file be located?
# default: CC_LOGFILE_DIR=$CC_INSTALL_DIR
CC_LOGFILE_DIR=$CC_INSTALL_DIR

#######################
# ENVIRONMENT ADDITIONS
# Add environement variables here that are needed by your build.
# example:
#  export JAVA_HOME=/usr/local/java
#
# or like this for local variables ONLY used in this file:
#  JAVA_HOME=/usr/local/java
# Add path to additional executables needed for project build.
# See PATH entry below for base config.
# No additional action taken when blank.
PATH_ADDITIONS=

##############################
# CRUISE CONTROL PORT SETTINGS
# Port for Jetty reporting application.
# default CC_WEBPORT=8080
CC_WEBPORT=8080
# JMX port for webapp.
# Change only if this port is in use as the webapp will also
# need modification.
# default CC_JMXPORT=8082
CC_JMXPORT=8082
# RMI port for webapp.
# Leave blank to disable.
CC_RMIPORT=

#######################################
# DO NOT MODIFY ENTRIES BELOW THIS LINE
NAME=cruisecontrol
DESC="CruiseControl - continuous integration build loop"
PATH=/sbin:/usr/sbin:/usr/bin:/bin
# add additions if variable has text defined
if [ -n "$PATH_ADDITIONS" ]; then
    PATH=$PATH_ADDITIONS:$PATH
fi
export PATH
CC_DAEMON=$CC_INSTALL_DIR/cruisecontrol.sh
CC_CONFIG_FILE=$CC_WORK_DIR/config.xml
CC_LOG_FILE=$CC_LOGFILE_DIR/cruisecontrol.log
CC_COMMAND="$CC_DAEMON -configfile $CC_CONFIG_FILE -webport $CC_WEBPORT -jmxport $CC_JMXPORT -rmiport $CC_RMIPORT"
# overwrite settings from default file
if [ -f /etc/default/cruisecontrol ]; then
  . /etc/default/cruisecontrol
fi
# does the executable exist?
test -f $CC_DAEMON || (echo "The executable $CC_DAEMON does not exist!" && exit 0)
if [ `id -u` -ne 0 ]; then
        echo "Not starting/stopping $DESC, you are not root."
        exit 4
fi
# Get the PID output from the startup script
if [ -f $CC_INSTALL_DIR/cc.pid ]; then
    CC_PID=`cat $CC_INSTALL_DIR/cc.pid`
else
    echo "No cc.pid file found.  CC process may not be controllable from this script!"
fi
case "$1" in
  'start')
   log_begin_msg "Starting Cruise Control..."
   cd $CC_INSTALL_DIR
   #echo "CC environtment at startup" > cc.startup.env
   #env >> cc.startup.env
   su $CC_USER -c "/bin/sh -c "$CC_COMMAND >> $CC_LOG_FILE 2>&1"" & RETVAL=$?
   #echo "$NAME started with jmx on port ${CC_JMXPORT}"
   log_end_msg 0
   ;;
 'stop')
   log_begin_msg "Stopping Cruise Control..."
   if [ -n "$CC_PID" ] && ps -p ${CC_PID} > /dev/null ; then
    kill -9 ${CC_PID}
     #$0 status
     RETVAL=$?
   else
     #echo "$NAME is not running"
     RETVAL=1
   fi
   log_end_msg 0
   ;;
 'status')
   if [ -n "$CC_PID" ] && ps -p ${CC_PID} > /dev/null ; then
     echo $NAME (pids $CC_PID) is running
     RETVAL=0
   else
     echo "$NAME is stopped"
     RETVAL=1
   fi
   ;;
 'restart')
   $0 stop && $0 start
   RETVAL=$?
   ;;
  *)
    echo "Usage: $0 { start | stop | status | restart }"
    exit 1
    ;;
esac
#echo ending $0 $$....
exit 0;

Apache Proxy Setup

To proxy CruiseControl requests through Apache, add a virtual host to your configuration:


<virtualhost *:80>
        ServerName cc.zunisoft.com
        ServerAdmin webmaster@zunisoft.com

       <location>
                Order deny,allow
                Deny from all
                AuthName "CruiseControl Login"
                AuthType basic
                AuthUserFile /etc/apache2/passwd
                Require valid-user
               Satisfy any
        </location>

        ProxyRequests          Off
        ProxyPreserveHost      On
        ProxyPass              / http://websvcs:8080/
        ProxyPassReverse       / http://websvcs:8080/

        ErrorLog /var/log/apache2/cc.error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/cc.access.log combined
        ServerSignature On
</virtualhost>

More Information

See the documentation for CruiseControl here.

To Top

Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *