Drupal Testing: PHP: 06: Jenkins & PHP ... Quite a few plugins to install

 


Required Jenkins Plugins

You need to install the following plugins for Jenkins:

You can install these plugins using the web frontend at

http://localhost:8080/pluginManager/available
or using the Jenkins CLI:

 

wget http://localhost:8080/jnlpJars/jenkins-cli.jar

java -jar jenkins-cli.jar -s http://localhost:8080 install-plugin checkstyle cloverphp crap4j dry htmlpublisher jdepend plot pmd violations warnings xunit

java -jar jenkins-cli.jar -s http://localhost:8080 safe-restart

If you see an error message such as "checkstyle is neither a valid file, URL, nor a plugin artifact name in the update center No update center data is retrieved yet", you need to update your plugin list manually:

curl -L https://updates.jenkins-ci.org/update-center.json | sed '1d;$d' | curl -X POST -H 'Accept: application/json' -d @- http://localhost:8080/updateCenter/byId/default/postBack

In the above, replace localhost:8080 with the hostname and port of your Jenkins installation.

Required PHP Tools

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.


Most web applications are changed and adapted quite 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 internal quality not only when developing, but also when maintaining the software.

Jenkins is the leading open-source continuous integration server. Thanks to its thriving plugin ecosystem, it supports building and testing virtually any project.

The goal of this project is to provide a standard template for Jenkins jobs for PHP projects.

Simply follow these four steps to get started:

  1. Install the required Jenkins plugins and PHP tools
  2. Orchestrate the PHP tools using Apache Ant
  3. Configure the PHP tools for use with Jenkins job template
  4. Create a Jenkins job for your PHP project

 

 


 

 

 

 


Most web applications are changed and adapted quite 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 internal quality not only when developing, but also when maintaining the software.

Many of the plugins referenced (right) can be used to integrate with PHP projects, but may first need to be configured the create appropriately formatted files when working with PHP projects.

Configuring PHP Tools

The configurations below assume the use of Apache Ant as the build tool for executing PHP tools. Originally described on jenkins-php.org.

PHPUnit

The phpunit task in the build.xml assumes that an XML configuration file for PHPUnit is used to configure the following logging targets:

<logging>
 <log type="coverage-html" target="build/coverage"/>
 <log type="coverage-clover" target="build/logs/clover.xml"/>
 <log type="coverage-crap4j" target="build/logs/crap4j.xml"/>
 <log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
</logging>

You can download a sample phpunit.xml.dist and place it in your project root to get started.

More information can be found in the documentation for PHPUnit.

phpDox

The phpdox task in the build.xml assumes that an XML configuration file for phpDox is used to configure the API documentation generation:

<phpdox xmlns="http://xml.phpdox.net/config">
 <project name="name-of-project" source="src" workdir="build/phpdox">
  <collector publiconly="false">
   <include mask="*.php" />
  </collector>

  <generator output="build">
   <build engine="html" enabled="true" output="api">
    <file extension="html" />
   </build>
  </generator>
 </project>
</phpdox>

More information can be found in the documentation for phpDox.

PHP_CodeSniffer

The phpcs and phpcs-ci tasks in the build.xml assume that an XML configuration file for PHP_CodeSniffer is used to configure the coding standard:

<ruleset name="name-of-your-coding-standard">
 <description>Description of your coding standard</description>

 <rule ref="Generic.PHP.DisallowShortOpenTag"/>
 <!-- ... -->
</ruleset>

The build script assumes that the rule sets for PHP_CodeSniffer is located at build/phpcs.xml.

More information can be found in the documentation for PHP_CodeSniffer.

PHPMD

The phpmd and phpmd-ci tasks in the build.xml assume that an XML configuration file for PHPMD is used to configure the coding standard:

<ruleset name="name-of-your-coding-standard"
  xmlns="http://pmd.sf.net/ruleset/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
                      http://pmd.sf.net/ruleset_xml_schema.xsd"
  xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
  <description>Description of your coding standard</description>

  <rule ref="rulesets/codesize.xml/CyclomaticComplexity" />
  <!-- ... -->
</ruleset>

The build script assumes that the rule sets for PHPMD is located at build/phpmd.xml.

More information can be found in the documentation for PHPMD.


 

 

 

Tags