Jenkins is the de-facto open source continuous integration server. Here's a quick guide to my experiences setting it up for releasing our guinea pig app, the AdWords Budget Tracker, a small Symfony2-based web tool.
Jenkins is the de-facto open source continuous integration server. Here's a quick guide to my experiences setting it up for releasing our guinea pig app, the AdWords Budget Tracker, a small Symfony2-based web tool. This exercise was part of an evaluation of tools for our new development environment. We'd like this environment to: • Make releases more reliable • Make releases faster • Automatically test code upon release, and email developers with the results • Provide more information to developers about the state of their codebase (e.g. conformity to coding standards, test coverage) • Help automate deployment • Use tools with a good reputation and solid user base • Use PHP and Linux What other technologies we might be using: • Symfony2 / Doctrine2 • GITSource Code Control • PHP Unit Testing Suite • Apache ANT Installing Jenkins The ultimate prerequisites to everything are PHP PEAR and the JDK. It's possible to install Jenkins without PEAR (as Jenkins itself is Java-based ) but you won't get very far, as many of the PHP Jenkins plugins we're going to use rely on it. Once the JDK was available, I was able to install Jenkins with a simple yum command (you might need apt-get if you're on Ubuntu). The Jenkins service can now be controlled using the service command at the command line:
sudo service jenkins restartYou should now have a running Jenkins web server. By default, Jenkins web service runs on port 8080. Jenkins' power comes from its library of plugins, and it couldn't be simpler to install a plugin. They can be installed via the command line but I used Plugin Manager in its web interface. There are a host of Jenkins plugins suited to the release of PHP. I installed: GIT Allows Jenkins to pull code from our GIT repository for release and for Jenkins to periodically check GIT for updates and trigger a build. xUnit Allows Jenkins to display PHP Unit XML output as reports etc on the project page. Clover PHP Allows us to show code coverage of our unit tests in report form using PHP Unit XML. Checkstyle Allows us to process PHP CodeSniffer outputs and show graphical reports. Apache Ant This plugin is pretty essential if we want to achieve anything. Jenkins can work with other build tools but due to its popularity, I chose Ant. An Ant build will be triggered by Jenkins, possibly when our GIT repository is updated, or manually by the user. The ant build script (an XML file) must be configured to execute various PHP tools that will provide data for the report plugins above. A failure at any stage of the build process can trigger a red flag which will mark the build as failed. The PHP tools triggered by Ant are as follows: Lint - Perform syntax checking Phpcs - Check adherence to coding standards Phunit - Run PHP unit tests We can also use Ant for automated deployment by pointing it at a simple deployment script. It would seem that if we have automated release tasks based on a GIT commit trigger then we would want a separate script to release code, using Jenkins with a separate Ant script. Useful (or not) Pointers • Make sure that your Jenkins user has permission to view the GIT repository • Demos on the web showing PHP/Jenkins don't go into much detail about phpunit, but the chances are, if you're using a framework like Symfony it won't be as simple as their example, you'll need to add a –c parameter to your Ant PHPUnit execute command to configure paths/includes for your framework and set the directory to your bundle tests only, otherwise, it will end up running all your framework tests