Tuesday 6 April 2010

CruiseControl

Continuous Integration With Cruise Control



Outline
0. Overview
1. Subclipse For Eclipse
2. Auomated Builds
3. Auomated Testing
4. Auomated Deployment

0. Overview
Problem Statement

Developing, building, testing, and deploying software presents a set of challenges as changes to the software are introduced.
Different versions of files must be tracked and tagged so there can be a snapshot of the software at a particular time. Without a snapshot, there is no point by which to know what version of the software is released.
Broken builds wastes time and money. In a team environment, developers often work on the same source files simultaneously. And if a developer does not have the latest working set of files, his or her build may break. Secondly, a developer may forget check in his or her changes, breaking the build for everyone. If the second case happens in a multinational corporation, much more time is lost due to developers working at different hours.
When a build is successful, new changes introduced in the build may break its intended functionality. Regression tests can catch when new changes break the intended functionality.

The Solution

The solution is to have a tight and continuous integrated development, build, test, and deployment environment as the software code is updated; errors or failures at any step of the cycle should inform interested parties so the failure can be addressed immediately. By immediately fixing the failure, it does not hold up other team members from continuing their work. One particular proposal is to integrate SVN, Subclipse (SVN plugin for Eclipse), Ant build scripts, and Cruise Control into the development, build, test, and deployment processes.
SVN can be used to manage different versions of the software, from each file to the entire project. Projects can be tagged, branched, and later merged back into the main line. However, SVN is commandline based and is not user friendly since developers have to type SVN operations by hand. Using the Subclipse plugin for Eclipse, the developer can interact with the code under development and SVN from a GUI perspective.
As code is checked into SVN, Cruise Control can automate builds at certain time intervals using Ant build scripts. Email alerts will be sent out to interested parties with each successful or failed build so that problems in the build can be addressed immediately.
Automated testing can be done in two ways. First, Cruise Control can be setup to run JUnit tests associated with each Java class. Of course, JUnit test cases would have to be written. Secondly, scripts can be written to run regression tests, such as Selenium test suites, whenever a new application is deployed or at scheduled intervals.
Cruise Control can be extended to process automated deployment of successful builds. TBD.


1 Subclipse For Eclipse
1.1 Installation

After starting up Eclipse, install the Subclipse plugin by selecting the menu item Help-->Install New Software. Type in the url http://subclipse.tigris.org/update_1.6.x in the "Work With" textfield and follow the installation wizard.


1.2 SVN Operations

Before starting, we must create a new project checked out from SVN. Select File-->New-->SVN-->Checkout Projects From SVN.


Then create a new SVN repository to checkout from or select from an existing one.


Once the project is checked out in Eclipse, the developer can modify files and Commit them to SVN. Other common operations include updating to the latest revisions (HEAD), synchronizing with the repository, and working off of branches and tags.


To create a branch, select Team-->Branch/Tag and enter the url where the branch should be created.


To switch to a branch, select Team-->Switch To A Branch/Tag/Revision.


After work on the branch is done, merging the branch code back into the main line can be done by selecting Team-->Merge. From the Merge GUI, select "Reintegrate a branch".


2 Automated Builds
2.1 Ant build.xml File

The Ant build.xml file contains properties and tragets. Properties are key-value pairs. Targets are instructions on how to carry out tasks in the build process. Sometimes, targets have dependencies on other targets to be executed first. In the build.xml file below, the "main" target depends on other targets such as clean, copy, compile, war, and delete all of which are executed in the order listed.


This build.xml file will be used by Cruise Control to carry out the build.
2.2 Configuring Automated Builds in Cruise Control

To enable automated builds, modify Cruise Control's config.xml file by adding the particular SVN project parameters. There are many configuration parameters to set but there are a few noteworthy ones to highlight. First is the svnbootstrapper parameter which specifies to do an svn update on the project or file prior to each build attempt. The svn modificationset parameter instructs Cruise Control to check with svn to detect any modifications since the last build. If there are modifications, then the schedule parameter specifies how to do the build. In the example config.xml file below, ant is called on the build.xml file executing the main target. The artifactspublisher specifies the file created from the build. Who to email after each build attempt can be specified in the email parameter.


2.2Cruise Control UI

The Cruise Control UI is straighforward. From the Dashboard, a list of projects and the status of their last build is displayed. To view details builds for a particular project, click on that project. For a particular build, the user can view modifications of source files since the last build, the build log, test results, and any errors and warnings. To force a build, click on the cirucluar arrow.

No comments: