PHPBuilder - Getting Started with Jenkins for PHP Developers

RSS Twitter
Articles Site Operation

Getting Started with Jenkins for PHP Developers

by: W. Jason Gilmore
June 21, 2011

The maturing Web development industry is inextricably intertwined with a constant companion: complexity. Gone are the days of assembling a few simple database-backed PHP-driven pages and calling it a website; these days clients expect rich JavaScript-based user interfaces, cloud-backed data stores, and tight integration with third-party APIs. To accommodate such challenges, developers have put a great deal of time and effort into devising tools and techniques which help to identify, track and resolve bugs. One such technique is continuous integration, which facilitates the merging of code changes made by various members of a development team by automating tedious processes such as testing, documentation generation, and deployment.

One popular continuous integration tool is Jenkins. (Jenkins is a recent fork of another continuous integration project named Hudson.) Although a Java-based solution, an active plugin community has made it possible to use Jenkins for far more than Java-specific projects. More recently it has become much easier for Jenkins' novices to use the project in conjunction with PHP projects thanks to the work of Sebastian Bergmann. Known as Template for Jenkins Jobs for PHP Projects, the project provides a configuration file which you'll use to enable Jenkins/PHP integration, and supports several popular familiar PHP tools such as PHP_CodeSniffer and PHPUnit. In this article I'll introduce you to just a few of the great ways you can begin using Jenkins in conjunction with your future PHP projects.

Installing Jenkins

Jenkins is supported on a wide variety of platforms, including Windows, Linux, and OS X. Head over to the official website to download the appropriate version. You'll also need to install a JDK if one isn't already installed. If you are using a Linux-based system then Jenkins is likely available via your package manager. For instance I used the following sequence of commands to install Jenkins on my Ubuntu laptop:

$ wget -q -O - | sudo apt-key add -
$ sudo su
$ echo "deb binary/" > /etc/apt/sources.list.d/jenkins.list
$ exit
$ sudo apt-get update
$ sudo apt-get install jenkins

Once installed Jenkins will automatically start and additionally be configured to automatically start as a service upon reboot. Next, head over to http://localhost:8080/ to begin the configuration process.

Next you'll need to configure Jenkins using Template for Jenkins Jobs for PHP Projects. This is actually a fairly involved process requiring you to install several PEAR packages and Jenkins plugins. Although Sebastian has done a thorough job documenting this process, there are a few missing details which will likely trip up those unfamiliar with the aforementioned PEAR packages. Therefore in addition to reviewing the instructions found at the project website, I also suggest reading Volker Dusch's excellent writeup.

Configuring Git Version Control System with PHP

If you're using Git for source control, you'll want to install Jenkins' Git plugin. The aforementioned documentation explains how to install Jenkins plugins. If you are using Git, one common source of confusion involves defining the project repository location. You have the option of identifying the location using URLs or local paths. When using the latter, you need to prefix the path with file://, for instance file:///

After restarting Jenkins, define Jenkins' Git username and email address by entering Jenkins' Web interface and navigating to Manage Jenkins > Configure System and setting these values under the Git plugin section. Performing this last step is important because neglecting to do so will cause your builds to fail due to Jenkins' inability to access the project log and tag the project due to Git complaining about the lack of a proper username.

Next Page »

Comment and Contribute

Your comment has been submitted and is pending approval.

W. Jason Gilmore



(Maximum characters: 1200). You have characters left.