test.ical.ly | getting the web by the balls

Aug/10

23

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!

Goal

What I want to achieve is to setup a project for my symfony plugin sfImageTransformExtraPlugin using the Sebastians template.

Prerequesites

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).

Conclusion

This template makes setting up Hudson for PHP development so much easier! Great thanks to Sebastian for his awesome work!

· · · · · · · · ·



  • Anton

    Christian, your tutorial worked great. The only problem I have now is that I don’t see any links to the reports showing up in the dashboard. Do you have any ideas on what would cause this? My project is building just fine, so that cannot be the issue.

  • http://test.ical.ly Christian

    @Anton did you do the last stept from Sebastians README?
    Activate “Use publishers from another project” and select php-hudson-template as the “Template Project”.

  • Anton

    Yup, that was it. I had used ‘use builders from another project’ instead of publishers from another project. Isn’t it always the small little things that get you? Thanks, Christian

  • Pankaj Lele

    Hello Christian,

    I am using the same “Use publishers from another project” and using “php-hudson-template” which works great for any project. Additionally I need to activate Email publishers to send email to developers when build fails etc. But what I see from the Template Project plugin is that you cannot activate other publishers after you activate “Use publishers from another project”. Is there any workaround for it or I have to modify “php-hudson-template” to activate additional publishers? Thanks in advance :)

  • http://test.ical.ly Christian

    @Pankaj that’s actually a problem I didn’t face so far. I think you should shout out to Sebastian Bergmann who created that template to find a solution. He’s also the creator of PHPUnit so you should be able to find his contact over his website, GitHub or twitter.

  • Pingback: Installing Hudson CI-Server on Gentoo Linux « Mohiva labs

<<

>>

Theme Design by devolux.nh2.me