Continuous Integration is one of the principles of Extreme Programming. Continuous Integration helps in bringing up the integration issues early on in the project and resolves them early so that there are no surprises when the project is deployed on the server. Martin Fowler’s site has this article on Continuous Integration that explains in detail the process and benefits behind Continuous Integration. We have a setup a continuous integration environment for J2EE projects with the help of following tools.
- Subversion - Subversion is an open source version control system that can keep track of the code changes. The developers commit their code to this version control system which is located on a server.
- Maven - Maven is a project management automation tool that also helps in packaging the application. Our projects are mavenized and follow the Apache packaging structures. Look at my build automation series of posts to know more about mavenizing a project.
- LuntBuild - LuntBuild is a J2EE based tool that helps in scheduling and executing build automation. It supports build automation tools like Ant and Maven and has a web user interface to configure and manage the schedules. We have a nightly build schedule and continuous integration schedule.
This is what happens in our continuous integration environment. When a developer has completed his/her code he/she runs maven on his/her desktop. Maven runs the unit tests, packages and deploys the application on an application server on the desktop. Once the build is successful and the developer is happy with the results he/she synchronizes his/her code with the Subversion repository. If there are any modifications to the mainline code (the latest and greatest available in the repository), he/she updates the code from the repository to the local environment. He/She again runs the maven script locally to make sure still the build is intact and works fine without any problems. If there are errors then those are fixed until the build is successful on his/her desktop. Once the build is successful on his/her desktop he/she commits the code to the Subversion code repository.
In the development server we have LuntBuild installed and configured to manage build automation schedules. A schedule is similar to UNIX cron job that gets triggered every 15 minutes. The project’s details and the Subversion details are configured in LuntBuild. When the schedule is kicked off a process determines if there is a change in the Subversion repository since the last build. If no change is detected then it goes to the sleep mode. If a change is detected, it gets the mainline code (latest) from the Subversion repository and triggers maven. Note that the maven project object model (pom.xml) is also part of the code and gets checked in into the Subversion. If the build is successful, the build output (an enterprise archive file) is copied to the JBoss application server’s directory. Since JBoss has hot deployment feature (with this I don’t need to restart the application server when I want to deploy a new version of the application. It sniff’s changes and picks up the changes automatically) the integrated application is available for testing. LuntBuild sends out a mail to the developers whether the build was successful or failure. If the build is a failure then the developers take appropriate action by looking at the build logs and correct the issues.
Since Maven runs automated unit tests and also generates test results, site documentation of the build and API documentation, it is linked from our project wiki site so that anybody in the team can see what the latest with the application is. Since the site generation would require some additional time in the overall build process this is done only during the nightly build (this is another schedule configured in LuntBuild that gets triggered midnight every day).
Some discipline would be required from the team in order to use continuous integration effectively. This article from Martin Fowler points out the disciplines required to have an effective continuous integration environment.