Setting up Continuous Integration for a symfony plugin using Hudson and Sebastian Bergmanns (PHPUnit) Template for Hudson Jobs for PHP Projects
I must admit that I have been lazy with my efforts on continuous integration lately. Eventually my server crashed unnoticed and I didn’t get any emails about broken builds anymore and by now I think I’ve stacked up some work to do.
First of course I’ve got to get my CI server up and running again, that’s why I installed Hudson again.
But there is room for improvement too. Sebastian Bergmann of PHPUnit fame spent some time on a template Hudson job for PHP projects that includes much more than PHPUnit. So I decided to use that!
What I want to achieve is to setup a project for my symfony plugin sfImageTransformExtraPlugin using the Sebastians template.
I am assuming that you already have a working Hudson installation and the following plugins installed:
- Checkstyle (for processing PHP_CodeSniffer logfiles in Checkstyle format)
- DRY (for processing phpcpd logfiles in PMD-CPD format)
- HTML Publisher (for publishing the PHPUnit code coverage report, for instance)
- JDepend (for processing PHP_Depend logfiles in JDepend format)
- PMD (for processing phpmd logfiles in PMD format)
- Template Project (for using php-hudson-template as a template for Hudson jobs)
- Violations (for processing various logfiles)
- xUnit (for processing PHPUnit logfiles in JUnit format)
Setting up the template job
Just as described in the README on GitHub we just checkout the project in to our Hudson jobs folder.
$ cd /home/of/hudson/jobs $ git clone git://github.com/sebastianbergmann/php-hudson-template.git
And then we have to restart Hudson to take notice of this new job.
The job itself is disabled as it has no subject.
Setting up the real job
So what I want to do is to checkout the current development version of my symfony plugin from GitHub. I also have to checkout it dependencies which are symfony itself and sfImageTransformPlugin which both are available only via Subversion.
I start by adding a new “free-style software project” job with the name “sfImageTransformExtraPlugin”.
First I configure the GitHub source and under the advanced options I configure it to be checked out into a local subdirectory “sfImageTransformExtraPlugin”.
Next I add a build step “Invoke Ant” and under advanced options I point it to the build.xml at “sfImageTransformExtraPlugin/build.xml”.
Last thing to configure is to “Use publishers from another project” and I enter “php-hudson-template” as the template project.
And that all you have to do to setup the project in Hudson.
But of course that’s not all. Two produce all the reports that the template should process and to checkout and update the dependencies we need two more configuration files which are both part of the plugin.
This is more or less a copy of the example from Sebastians GitHub Page with soem slight modifications.
The first target “update” will check out the dependencies from symfonys Subversion repositories in parallel to the plugin itself. The plugin is configured to assume symfony and sfImageTransformPlugin at these locations.
All artifacts such as coverage reports and metrics will be written to a directory “build” which also lies in parallel to the plugin source. All together will produce a directory structure like this.
/path/to/hudson/jobs/sfImageTransformExtraPlugin/build/ /path/to/hudson/jobs/sfImageTransformExtraPlugin/sfImageTransformExtraPlugin/ /path/to/hudson/jobs/sfImageTransformExtraPlugin/sfImageTransformPlugin/ /path/to/hudson/jobs/sfImageTransformExtraPlugin/symfony/
But not all reports that are expected by the template are being produced by this build.xml. The PHPUnit specific reports are configured in the phpunit.xml file.
Adjust these two configuration files for your plugin to your needs and you’re ready to go.
In the following weeks I will write some posts explaining all the results you can now see in your Hudson installation (or in mine).
This template makes setting up Hudson for PHP development so much easier! Great thanks to Sebastian for his awesome work!