Sheila's Blog

Software Development

Sheila's Blog header image 2

Setting up an Automated Build System

June 9th, 2009 by Sheila

Many teams apply continuous integration as part of their software development process.  This means that each team member integrates their work regularly.  To facilitate doing this, you first need an automated build script that each developer can use to compile and build the code locally.  If there are no issues, then the developer can check in their code.  At this point you want an automated build system that takes the latest code from source control and builds it, notifying the team if there are any errors.  The advantage of such an automated build system is that teams are notified early on if there are any integration issues rather than just before a  release deadline.  The build machine also serves as a fully deployed example of the latest version.  When a team member says that a piece of work is completed it should be verified on this machine – not their own.

Cruisecontrol is an open source continuous integration tool.  It allows you to monitor a project, building it when files are updated and notifying you if any part of the build process fails.  There are a lot of reporting tools that can be run on your build.  Unit tests, cover coverage and analysis tools and java documentation are useful to add to your build and make available in your reporting application.  These can be integrated into cruisecontrol.

This post assumes that you are installing cruisecontrol on a redhat machine and that you deploy your application to JBoss.  Any necessary databases have been installed and configured, and you have an ant build script for building and deploying the application.  You have also created a user called cruise that will run the automated build.

Install Java
Download jdk-6u13-linux-i586.bin to /home/cruise
Type sh jdk-6u13-linux-i586.bin
Accept the license agreement
Java will install into the cruise home directory
JAVA_HOME = /home/cruise/jdk1.6.0_13

Install JBoss
Download jboss-4.2.2.GA.zip to /home/cruise
unzip jboss-4.2.2.GA.zip
To avoid any permgen memory errors edit JBOSS_HOME/bin/run.conf and set the following Xms, Xmx, PermSize and MaxPermSize values

Install Ant
Download apache-ant-1.7.1-bin.tar.gz to /home/cruise
gunzip apache-ant-1.7.1-bin.tar.gz
tar -xvf  apache-ant-1.7.1-bin.tar

Configure paths and settings for the user
You need to configure the .bashrc for the cruise user (assuming the user shell is bash)# .bashrc # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi # User specific aliases and functions export JAVA_HOME=/home/cruise/jdk1.6.0_13 export ANT_HOME=/home/cruise/apache-ant-1.7.1 export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server export JBOSS_HOME=/home/cruise/jboss-4.2.2.GA export PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$ORACLE_HOME/bin:$JBOSS_HOME/bin:$PATH
Install subversion
Subversion should already be available, check this by running 'rpm -q subversion'
and making sure it returns a value

Install cruisecontrol
Download cruisecontrol-src-2.8.2.zip to /home/cruise
unzip cruisecontrol-src-2.8.2.zip
Type ant in /home/cruise/cruisecontrol-2.8.2/main

Configure the build projects
mkdir /home/cruise/build
mkdir /home/cruise/build/artifacts
mkdir /home/cruise/build/logs
mkdir /home/cruise/build/projects

Configure a new project
For a project called 'projectname', in /home/cruise/build/projects/projectname you should check out the source code eg.
svn checkout http://svn.company.com/project/trunk
Configure the project settings and test the build script to verify that it works without errors.

Configure CruiseControl
You will need to create a file called build-projectname.xml <!-- Delegating build script, used by cruisecontrol to build the project. Note that the basedir is set to the checked out project --> <project name="build-projectname" default="automatedbuild" basedir="/home/cruise/build/projects/projectname"> <target name="automatedbuild"> <!-- Get the latest from SVN --> <exec executable="svn"> <arg line="up --username user --password pass"/> </exec> <!-- Call the target that does everything --> <ant antfile="build.xml" target="clean-deploy"/> </target> </project>

Edit this file to match your own settings and set the correct username/password for subversion.

Now you need to create the config.xml that is used by cruisecontrol: <cruisecontrol> <!-- Schedule each project to check for modifications every 15 mins and build if modifications have been made --> <project name="projectname" buildafterfailed="true" requiremodification="true"> <plugin name="svn" classname="net.sourceforge.cruisecontrol.sourcecontrols.SVN"/> <listeners> <currentbuildstatuslistener file="logs/projectname/status.txt"/> </listeners> <modificationset quietperiod="180" ignoreFiles="*/projectname/db/**"> <svn localworkingcopy="projects/projectname"/> </modificationset> <schedule interval="900"> <ant anthome="/home/cruise/apache-ant-1.7.1" buildfile="build-projectname.xml" target="automatedbuild" uselogger="true" usedebug="false"/> </schedule> <log logdir="logs/projectname"> <delete every="1" unit="MONTH"/> <merge dir="projects/projectname/reports/junit/"/> <merge file="projects/projectname/reports/checkstyle/cs_errors.xml"/> <merge dir="projects/projectname/reports/metrics/"/> <merge dir="projects/projectname/reports/cobertura/"/> </log> <publishers> <htmlemail mailhost="xxx.xxx.x.x" username="emailuser" password="emailpass" returnname="CruiseControl" returnaddress="<em>user@company.com</em>" reportsuccess="always" subjectprefix="CruiseControl: Projectname - " buildresultsurl="http://xxx.xxx.x.x:8080/cruisecontrol/buildresults/projectname" skipusers="true" spamwhilebroken="false" logdir="logs/projectname" xsldir="/home/cruise/cruisecontrol-2.8.2/reporting/jsp/webcontent/xsl" css="/home/cruise/cruisecontrol-2.8.2/reporting/jsp/webcontent/css/cruisecontrol.css"> <always address="user@company.com" /> <failure address="teamlist@company.com" reportWhenFixed="true"/> </htmlemail> </publishers> </project> </cruisecontrol>

Edit this again to suit your own settings.  Refer back to the cruisecontrol documentation for further information on the settings above, but this will check for updates to the source code every 15 mins.  If there are changes then the build will be run.  If the build fails then the team is emailed.  If it's successful then someone who monitors the build system can be emailed.

Start CruiseControl

To test the cruisecontrol configuration you need to execute cruisecontrol.sh from /home/cruise/build
First set the permissions with chmod a+x /home/cruise/cruisecontrol-2.8.2/main/bin/cruisecontrol.sh
Then run
/home/cruise/cruisecontrol-2.8.2/main/bin/cruisecontrol.sh

Configure Reporting
Type ant in
/home/cruise/cruisecontrol-2.8.2/reporting/jsp

You will be asked for these parameters:
log.dir: /home/cruise/build/logs
status.file: status.txt
artifacts.dir: /home/cruise/build/artifacts

Copy /home/cruise/cruisecontrol-2.8.2/reporting/jsp/dist/cruisecontrol.war to the jboss deploy directory

Start up jboss and you should be able to access cruisecontrol at http://xxx.xxx.x.x:8080/cruisecontrol/

Tags: 2 Comments

Leave a Comment

2 responses so far ↓