/ build

continuous integration for PHP

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

What we will do is install a jenkins build server, configured to build a common PHP project. Jenkins then uses its plugin infrastructure to maintain the code through various code checks:

Jenkins installation

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 /Users/<your-user-name>/.jenkins/jobs/

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.