Setting up Jenkins Continuous Integration for a PHP project on a Mac Mini Server


With one of my previous post I have run through the steps involve in setting up Jenkins and today I’m going to discuss about the how to get a PHP project integrated with Jenkins on a Mac Mini server(It’s a pain in the ass compared to a Linux box when it comes to setting up Jenkins server).

List of items required

We need to enable and install following modules both on Jenkins as well as on PHP.

  • Jenkins
    • Checkstyle
    • CloverPHP
    • Dry
    • HTML Publisher
    • JDepend
    • Plot
    • PMD
    • Violation
    • xUnit
    • JSHint Report
    • Apache Ant
    • Subversion
    • Jenkins Email Extension
  • PHP modules using the PEAR package
    • phploc
    • pdepend
    • phpmd
    • phpcs
    • phpcpd
    • phpdox
    • phpunit
    • phpcb

Install modules and plugins

Alright, we have list down the items and now lets see how to install each items.

Installation of Jenkins modules

Navigates to Jenkins » Manage Jenkins » Plugin Manager.

Under this section you’ll find four tabs, namely Updates, Available, Installed, Advanced. Select Available tab and tick the above mentioned list of plugins from the list and click on the Install without restart button.

Installation of required PHP modules via PEAR package

Please make sure that you have installed the PHP PEAR package before proceeding with the below steps.

  • phploc – A tool for quickly measuring the size of a PHP project.
    $ sudo pear config-set auto_discover 1
    $ sudo pear install pear.phpunit.de/phploc
  • pdepend – Metrics analysis tool for software developed in PHP.
    $ sudo pear channel-discover pear.pdepend.org
    $ sudo pear install pdepend/PHP_Depend-beta
  • phpmd – It takes a given PHP source code base and look for several potential problems within that source.
    $ sudo pear channel-discover pear.phpmd.org
    $ sudo pear install phpmd/PHP_PMD
  • phpcs – It tokenises PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.
    $ sudo pear install PHP_CodeSniffer
  • phpcpd – It is a Copy/Paste Detector (CPD) for PHP code.
    $ pear install pear.phpunit.de/phpcpd
  • phpdox – It is a documentation generator for generating API documentation in HTML format, for instance, from PHP source code.
    $ sudo pear install -f pear.netpirates.net/phpDox-0.5.0
  • phpunit – It is a documentation generator for generating API documentation in HTML format, for instance, from PHP source code.
    $ sudo pear channel-discover pear.phpunit.de
    $ sudo pear install phpunit/PHPUnit
  • phpcb – It is a documentation generator for generating API documentation in HTML format, for instance, from PHP source code.
    $ sudo pear channel-discover pear.phpqatools.org
    $ sudo pear install --alldeps phpqatools/PHP_CodeBrowser

Fixing the issue:
When you execute Build Now from the project’s menu you’ll notice that following message is displayed under Console Output section.

phpcpd:
     [exec] Warning: require(PHPCPD/Autoload.php): failed to open stream: No such file or directory in /usr/bin/phpcpd on line 49
     [exec] Fatal error: require(): Failed opening required 'PHPCPD/Autoload.php' (include_path='.:') in /usr/bin/phpcpd on line 49

Where ever your encounter a similar error please place the following block of code on the top of the respective script. This required script can be found under /usr/bin. For example with phpcpd place the following block of code.

$path = '/usr/lib/php';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);

Preparation of the build script

I used the Template for Jenkins Jobs for PHP Projects for preparing the build script. The site provides a comprehensive guide to create the build script for Apache Ant.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: