Why Continuous Integration?
Most web applications are changed and adapted frequently and quickly. Their environment, for example the size and the behaviour of the user base, are constantly changing. What was sufficient yesterday can be insufficient today. Especially in a web environment it is important to monitor and continuously improve the software quality not only when developing, but also when maintaining the software. The practice of Continuous Integration is the solution of choice to achieve this goal.
Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least dailyleading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration errors as quickly as possible. |
-- Martin Fowler |
Continuous Integration reduces the amount of repetitive processes the developers need to perform when building or deploying the software thus reducing the risks of late discovery of defects, producing low-quality software, lack of project visibility as well as lack of deployable software.
Why Jenkins?
At least as far as I know, Sebastian Nohn was the first to experiment with the continuous integration of PHP projects. Back in 2006 he described on his blog how to use Apache Ant and CruiseControl to set up a continuous build that invoked PHPUnit to run the unit tests of a PHP project.
Soon thereafter, the developers of Mayflower GmbH started to build a quality assurance platform for PHP projects that was based on CruiseControl. It not only ran unit tests as part of the build loop but also static code analysis tools such as PHP_CodeSniffer to collect software metrics over time.
This quality assurance platform gave Manuel Pichler the idea to start the phpUnderControl open source project. This was a set of patches for CruiseControl (which could not be customized or extended through plugins) that added out-of-the-box support for PHP projects. phpUnderControl significantly lowered the barrier to entry for introducing continuous integration into a PHP project but since it was based on CruiseControl it was a nightmare from an operations point of view and not as customizable and flexible as one would like.
The developers of Mayflower GmbH later refactored their quality assurance platform for PHP projects into a tool that can be used with arbitrary continuous integration servers. It was open-sourced under the name PHP_CodeBrowser.
When the Java community started to migrate from CruiseControl to more modern continuous integration servers, I had a look at Hudson (as Jenkins was called back then) and tried it together with the PHP quality assurance toolchain. I was pleasantly surprised to find a product that was not only more convenient to use and more robust (from an operations perspective) than CruiseControl but to also meet a vibrant development community. Thanks to the plethora of plugins developed and maintained by this community, Jenkins supports building and testing virtually any project, including PHP projects.
The PHP community has developed a wide range of quality assurance tools since 2006. Where Sebastian Nohn only ran PHPUnit tests with Apache Ant and CruiseControl, a typical continuous integration setup for a PHP project today also includes the detection of violations of a defined set of coding guidelines and the gathering of various software metrics as well as the generation of API documentation, for instance.
Over the course of the last two years I have successfully set up continuous integration environments that are based on Jenkins for our customers. These development teams leverage Jenkins to monitor the various aspects of software quality throughout the lifecycle of their projects. This enables them to create, maintain and extend sustainable software of high quality with PHP. The result of this experience is a template for Jenkins jobs for PHP projects that I have released as an open source project.
What's in This Book?
This book covers everything you need to know in order to use Jenkins for the continuous integration of your PHP projects. Here is how the book is organized:
In this chapter you will learn how to use Apache Ant to automate your build.
This chapter explains how to set up Jenkins and install the PHP tools that are required to continuously integrate a PHP project.
This chapter shows how to create a job for a PHP project in Jenkins.
Building on the continuous integration environment that was set up in the previous chapter, you will learn in this chapter how to add static code analysis tools to the build for continuous inspection.
This chapter shows how the automated build and continuous integration of a PHP project can be simplified by using the PHP Project Wizard and the Template for Jenkins Jobs for PHP Projects .
This chapter concludes the book with a summary of the benefits of Continuous Integration and Continuous Inspection while providing an outlook of what you can implement in addition to the processes and techniques described in this book.
This book makes the assumption that the reader is familiar with the concept of Continuous Integration and the set of problems it aims to solve. [] are recommended basic and further reading, respectively, on this topic.
While this book explains how to install Jenkins and how to configure it for PHP jobs it does not cover topics such as authentication, for instance, that are impartial to the programming stack used. Furthermore, the assumption is made that Jenkins is installed in a UNIX environment. For Jenkins-related topics not covered in this book the reader is referred to [].
The planning, execution, and automation of tests for the different layers and tiers of a PHP-based web application is also outside the scope of this book. [] is an excellent resource on these matters.
Finding Out More
If you would like to find out more about Jenkins and PHP, and to get the latest updates, visit this book's companion website at http://jenkins-php.org/. This is also where the template for Jenkins jobs for PHP projects is maintained.
Conventions Used in This Book
The following typographical conventions are used in this book:
Italic
Indicates new terms, URLs, email addresses, filenames, and file extensions.