Continuous Integration with Flex – Part 5

This is the penultimate installment of the CI saga, and its the last step you will need to take to get your continuous integration suite up and running. The first thing you will need to do is install CruiseControl onto your build monitoring machine. The first thing I did was get it up and running on my machine, and then re-follow my steps on a server.

CruiseControl is an open source build monitoring tool. The good thing about it is that it can be easily configured using an XML file, has plugins to lots of other tools , and has a simple to understand web based interface. I just installed from the binaries, and followed these quickstart instructions. One thing I did have to do that wasnt covered in the instructions is set an environment variable, JAVA_HOME to the location of java on my machine (in my case: C:Program FilesJavajdk1.5.0_04 ). Once you have it up and running with the simple connectfour example, we are ready to get going with our flex project.

Check out the project repository to cruisecontrol’s projects folder

The first step is to create a new folder in the ‘projects’ folder of cruisecontrol and check out your project to that folder. This is the copy of the repository that cruisecontrol will be using to run the master build. The name of the folder will be the same as the name displayed by Cruisecontrol for your project.

Copy your required classes to the ant directory of Cruise Control

Remember those ant classes I got you to download and put in the lib folder for your local build? Well, cruise control is going to need them too if its going to build successfully. so, look for the ant folder in cruisecontrol (apache-ant-1.6.5lib) and put the classes you downloaded in step 2 in there.

Make your build CruiseControl happy

CruiseControl checks at specified intervals to see if any changes have been made to your source code, then it will trigger a build. This is all well and good, but the main thing to consider is that even though cruisecontrol will know to trigger a build if the source code has changed, it does not automatically do an update from the repository. So before we go any further with cruise control, add the following target to your ant build:

<target name="update">
<svn>
<update dir="${basedir}" />
</svn>
</target>

And change your ‘all’ target (again) to look like this:

<target name="all" depends="update,determineTestHarnessSuccess,compileMain"/>

Be aware though that this solution is not ideal. If you change anything the ant script needs before it runs, these will not be up to date (until the next time the ant script runs) for example, your build properties file, or any jar’s referenced and stored in the repository. In practice, this shouldn’t happen too much, and isn’t worth worrying about (too much)…

Configure CruiseControl

The next step is to configure cruise control for your needs… First off, to get somewhere, you will need a place for logs to be put so that CruiseControl can read them and tell you how your app is doing. Make a folder in the logs directory with the same name as the one you made in the projects folder. You will probably want to publish build artifacts too. Basically, when CruiseControl has a successful build (or even an unsuccessful one if you like), it can publish artifacts by copying a file or directory somewhere. This is incredibly useful for tracking the progress of a project, as you get to see a snapshot of your project at each successful build. Go ahead and make a folder in the artifacts folder of cruise control and give it the same name as the folder in projects…

Now we need to write our config XML for the project. This is a relatively simple affair, but will be different according to your needs. Open up config.xml in the cruisecontrol directory and take a look at how its setup for connectfour (the sample project). We setup our build to run every 15 minutes, publish successful builds to the artifacts directory and mail the project team the results of the build, but you can set it up to do pretty much what you like… The configuration reference is invaluable for showing you what you can do with CruiseControl… Below is an outline of how we set our build up:

<cruisecontrol>
<project name="testFlexProject" buildafterfailed="false">
<listeners>
<currentbuildstatuslistener file="logs/${project.name}/status.txt"/>
</listeners>
<!-- Bootstrappers are run every time the build runs,
*before* the modification checks -->
<bootstrappers>
<svnbootstrapper
file="projects/${project.name}/build.xml"/>
</bootstrappers>
<!-- Defines where cruise looks for changes, to decide
whether to run the build -->
<modificationset quietperiod="10">
<svn localworkingcopy="projects/${project.name}"/>
</modificationset>
<!-- Configures the actual build loop, how often and which
build file/target -->
<schedule interval="900">
<ant anthome="K:cruisecontrolcruisecontrol-bin-2.4.1apache-ant-1.6.5" buildfile="projects/${project.name}/build.xml" target="all" uselogger="true" usedebug="true"/>
</schedule>
<!-- directory to write build logs to -->
<!-- log logdir="logs/${project.name}"/ -->
<log>
<merge dir="projects/${project.name}/log/test-results"/>
</log>
<!-- Publishers are run *after* a build completes -->
<publishers>
<onsuccess>
<artifactspublisher dest="artifacts/${project.name}" dir="projects/${project.name}/bin"/>
<htmlemail mailhost="YOURMAILHOSTHERE" returnaddress="richard.nixon@YOURCOMPANY.com" returnname="Nixon" buildresultsurl="CRUISECONTROLIPADDRESS:8080/buildresults/${project.name}" skipusers="true" xsldir="C:/cruisecontrol/cruisecontrol-bin-2.4.0/webapps/cruisecontrol/xsl" css="C:/cruisecontrol/cruisecontrol-bin-2.4.0/webapps/cruisecontrol/css/cruisecontrolEmail.css">
<always address="youremailinhere"/>
</htmlemail>
</onsuccess>
<onfailure>
<htmlemail mailhost="YOURMAILHOSTHERE" returnaddress="richard.nixon@YOURCOMPANY.com" returnname="Nixon" buildresultsurl="CRUISECONTROLIPADDRESS:8080/buildresults/${project.name}" skipusers="true" xsldir="C:/cruisecontrol/cruisecontrol-bin-2.4.0/webapps/cruisecontrol/xsl" css="C:/cruisecontrol/cruisecontrol-bin-2.4.0/webapps/cruisecontrol/css/cruisecontrolEmail.css">
<always address="youremailinhere"/>
</htmlemail>
</onfailure>
</publishers>
</project>
</cruisecontrol>

That is pretty much it – in our set up cruisecontrol checks the repository every 15 minutes for code changes, and if the build succeeds, everyone gets an email pointing them to the latest build results. It has already proved itself in the first few weeks of getting up and running – the project team now know where we are in a project, and know where to get hold of the latest build. On top of this, they can browse through previous builds and see exactly how we’re progressing…

This entry was posted in Continuous Integration, Flash & Actionscript. Bookmark the permalink. Comments are closed, but you can leave a trackback: Trackback URL.