- See the pain here: http://jenkins-php.org/
- And here: https://www.reddit.com/r/PHP/comments/31qw8h/setting_up_phpunit_and_jenkins/
- And here: https://modess.io/jenkins-php/
Installation
Required Jenkins Plugins
You need to install the following plugins for Jenkins:
-
Checkstyle (for processing PHP_CodeSniffer logfiles in Checkstyle format)
-
Clover PHP (for processing PHPUnit's Clover XML logfile)
-
HTML Publisher (for publishing documentation generated by phpDox, for instance)
-
JDepend (for processing PHP_Depend logfiles in JDepend format)
-
Violations (for processing various logfiles)
-
Warnings (for processing PHP compiler warnings in the console log)
You can install these plugins using the web frontend at
http://localhost:8080/pluginManager/available
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.
Template for Jenkins Jobs for PHP Projects
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:
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.
- Log in to post comments