Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NoodlesNZ/ea5ab91c03f4dfb13ca0 to your computer and use it in GitHub Desktop.
Save NoodlesNZ/ea5ab91c03f4dfb13ca0 to your computer and use it in GitHub Desktop.
Jenkins phpcs
<?xml version="1.0" encoding="UTF-8"?>
<project name="projectname" default="build">
<!-- Check for checkstyle report from previous build -->
<available file="${basedir}/build/logs/checkstyle.xml" type="file"
<target name="build"
<target name="tools-parallel" description="Run tools in parallel">
<parallel threadCount="2">
<!-- do other build targets (not included here)
<antcall target="pdepend"/>
<antcall target="phpmd-ci"/>
<antcall target="phpcs-ci"/>
<target name="clean" depends="phpcs-prep" description="Cleanup build artifacts">
<delete dir="${basedir}/build/logs"/>
<delete dir="${basedir}/build/pdepend"/>
<target name="prepare" depends="clean"
description="Prepare for build">
<mkdir dir="${basedir}/build/logs"/>
<mkdir dir="${basedir}/build/pdepend"/>
<target name="lint" description="Perform syntax check of sourcecode files">
<apply executable="php" failonerror="true">
<arg value="-l" />
<fileset dir="${basedir}/public_html">
<include name="**/*.php" />
<modified />
<target name="phpcs-prep" depends="phpcs-partial,phpcs-full" />
<target name="phpcs-partial" description="Partial phpcs runner" if="phpcs.checkstyle.exists">
<!-- Debugging message -->
<echo>Running Partial phpcs</echo>
<!-- Find changed files -->
<fileset dir="public_html/" id="phpcs.changedfiles">
<include name="**/*.php" />
<modified />
<!-- Find all files listed in the last checkstyle.xml report -->
<xmlproperty file="${basedir}/build/logs/checkstyle.xml"
collapseAttributes="true" delimiter=" "/>
<loadresource property="phpcs.checkstyle">
<propertyresource name=""/>
<replacestring from="/var/" to="var/"/>
<!-- Convert file list string to fileset -->
<!-- This removes files that don't exist on the file system -->
<fileset dir="/" id="phpcs.checkstylefiles" includes="${phpcs.checkstyle}"/>
<!-- Merge filesets -->
<union id="phpcs.files">
<resources refid="phpcs.changedfiles" />
<resources refid="phpcs.checkstylefiles" />
<!-- Convert merged file list to a string for phpcs -->
<pathconvert pathsep=" " property="phpcs.pathlist" refid="phpcs.files"/>
<!-- Change paths to relative -->
<loadresource property="phpcs.filelist">
<propertyresource name="phpcs.pathlist"/>
<replacestring from="${basedir}/" to=""/>
<target name="phpcs-full" description="phpcs full runner" unless="phpcs.checkstyle.exists">
<property name="phpcs.filelist" value="${basedir}/public_html/"/>
<target name="phpcs-ci"
description="Find coding standard violations using PHP_CodeSniffer">
<exec executable="phpcs">
<arg value="--report=checkstyle" />
<arg value="--report-file=${basedir}/build/logs/checkstyle.xml" />
<arg value="--standard=PEAR" />
<arg value="--extensions=php" />
<arg line="${phpcs.filelist}" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment