Home/Jenkins – Setting up a PHP project in jenkins

Jenkins – Setting up a PHP project in jenkins

Published On: 4 January 2017.By .
  • Product & platform Engineering

Pre-requisites –

For Setting up PHP project you need to install the following plugins for Jenkins:

  • DRY (for processing phpcpd logfiles in PMD-CPD format)
  • PMD (for processing PHPMD logfiles in PMD format)
  • Warnings (for processing PHP compiler warnings in the console log)

The following PHP tools are required:

We assume that these tools are on the $PATH and can be invoked with phpunit, phpcs, phploc, pdepend, phpmd, phpcpd, and phpdox, respectively. For instance because you have downloaded the respective PHP archives (PHAR) and put them into your $PATH or because you have installed the tools globally using composer.

Automation –

We use Apache Ant to automate the build process. It orchestrates the execution of the various tools in the build.xml build script (download). The build script assumes that the rule sets for PHP_CodeSniffer and PHPMD are located at build/phpcs.xml and build/phpmd.xml.

Executing the build.xml script will produce the following build directory:

|-- api ...
|-- coverage ...
`-- logs
   |-- checkstyle.xml
   |-- clover.xml
   |-- crap4j.xml
   |-- jdepend.xml
   |-- junit.xml
   |-- phploc.csv
   |-- pmd-cpd.xml
   `-- pmd.xml

These build artifacts will be processed by Jenkins.

Integration –

Using the Job Template

$ cd $JENKINS_HOME/jobs (NOTE : $JENKINS_HOME will be /var/lib/jenkins/)
$ mkdir php-template
$ cd php-template
$ wget https://raw.github.com/sebastianbergmann/php-jenkins-template/master/config.xml
$ cd ..
$ chown -R jenkins:jenkins php-template/

Now Do the following steps –

  1. Click on “New Job”.
  2. Enter a “Job name”.
  3. Select “Copy existing job” and enter “php-template” into the “Copy from” field.
  4. Click “OK”.
  5. Uncheck the “Disable Build” or “Disable this Project” option.
  6. Fill in your “Source Code Management” information.
  7. Configure a “Build Trigger”, for instance “Poll SCM”.
  8. Click “Save”.

Example –

The Money project is an example that uses the build automation.

Use 1-3 steps same as above steps and in step-4 select “git” in Source Code Management and add Repository URL – https://github.com/sebastianbergmann/money.git  and you can also configure many options there according to your need, then Click on “Save”. See reference screeshot –


Now click on “Build Now” to check whether the build is successful or not. You can see console output in Build History section.

For more information you can see here – http://jenkins-php.org/

Related content

We Love Conversations

Say Hello
Go to Top