Today I will introduce a fairly often discussed way of setting up a continuous integration infrastructure for PHP using jenkins as build server. Jenkins despite the old fashioned Java way is also capable of managing PHP projects, thus generating documentation and various code metrics as well as patrolling your code for malicious coding.
The tools we use in this tutorial will help to improve the managed PHP project by leveraging them to a stable continuous integration workflow.
But first things first
- Checkstyle (for processing PHP_CodeSniffer logfiles in Checkstyle format)
- Clover PHP (for processing PHPUnit code coverage xml output)
- 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)
- Plot (for processing phploc CSV output)
- PMD (for processing PHPMD logfiles in PMD format)
- Violations (for processing various logfiles)
- xUnit (for processing PHPUnit logfiles in JUnit format)
At first a stable installation of jenkins is necessary to set up a good foundation to build on. I will use Homebrew to install the latest jenkins:
In the next step I will install all necessary plugins via the jenkins CLI interface. It’s also possible to install the plugins via the web interface administration, but via CLI it’s a lot easier:
After the installation is done, your build server is ready to run.
Required PHP tools
As for jenkins, also for PHP are some required tools are mandatory. All required tools can be installed through PEAR, the PHP Extension and Application Repository. As the installation of this infrastructure will run on Mac OS X 18.8.4, we first need to upgrade by
sudo pear upgrade PEAR. To install the required tools simply use PEAR to install them:
PHP project template
Next we need to tell jenkins how to set up PHP project using a template to build all needed release artifacts. The following ant
build.xml can be used to archive this:
This script need to be copied to your jenkins jobs directory located at
After those commands are done, href=”http://jenkins-ci.org” target=”_blank”>jenkins should show us a deaktivated project called ci-template. This template can now be cloned to new PHP projects by simple calling the href=”http://jenkins-ci.org” target=”_blank”>jenkins CLI:
A new job
myProject should appear in your project list.