Installing Jenkins-PHP vs PHPUnderControl on CruiseControl on Windows XP

It’s easier to install and configure both on Linux but installing on Windows platform can be quite painful.

I started with PHPUnderControl and after some days I finally got it working but right after it started to successfully build my projects I found out that PHPUnderControl is not actively developed and somebody on Freenode said Jenkins is the way to go.

So good place to start for PHP programmers is http://jenkins-php.org/ but unfortunately example configuration did not work out of the box.

So here are some configuration file examples which worked for me on Windows XP:

PHPUnderControl:

config.xml:

<cruisecontrol>
<project name=”test.com”>

<listeners>
<currentbuildstatuslistener file=”logs/${project.name}/status.txt”/>
</listeners>

<bootstrappers>
<svnbootstrapper localWorkingCopy=”projects/${project.name}/source/” file=”build.xml”/>
</bootstrappers>

<modificationset quietperiod=”30″>
<!– touch any file in connectfour project to trigger a build –>
<filesystem folder=”projects/${project.name}”/>
</modificationset>

<schedule interval=”300″>
<ant anthome=”apache-ant-1.7.0″ buildfile=”projects/${project.name}/build.xml”/>
</schedule>

<log>
<merge dir=”projects/${project.name}/target/test-results”/>
</log>

<publishers>
<onsuccess>
<artifactspublisher dest=”artifacts/${project.name}” file=”projects/${project.name}/target/${project.name}.jar”/>
</onsuccess>
</publishers>

</project>
<project name=”connectfour”>

<listeners>
<currentbuildstatuslistener file=”logs/${project.name}/status.txt”/>
</listeners>

<bootstrappers>
<antbootstrapper anthome=”apache-ant-1.7.0″ buildfile=”projects/${project.name}/build.xml” target=”clean” />
</bootstrappers>

<modificationset quietperiod=”30″>
<!– touch any file in connectfour project to trigger a build –>
<filesystem folder=”projects/${project.name}”/>
</modificationset>

<schedule interval=”300″>
<ant anthome=”apache-ant-1.7.0″ buildfile=”projects/${project.name}/build.xml”/>
</schedule>

<log>
<merge dir=”projects/${project.name}/target/test-results”/>
</log>

<publishers>
<onsuccess>
<artifactspublisher dest=”artifacts/${project.name}” file=”projects/${project.name}/target/${project.name}.jar”/>
</onsuccess>
</publishers>

</project>
</cruisecontrol>

build.xml for test.com:

<?xml version=”1.0″ encoding=”utf-8″?>
<project name=”test.com” default=”build” basedir=”.”>
<target name=”checkout”>
<exec executable=”svn” dir=”${basedir}/source”>
<arg line=”up” />
</exec>
</target>
<target name=”php-documentor”>
<exec executable=”phpdoc.bat” dir=”${basedir}/source”>
<arg line=”-ct type -ue on -t ${basedir}/build/api -tb C:\php\pear\data\phpUnderControl\data\phpdoc -o HTML:Phpuc:phpuc -d ./” />
</exec>
</target>
<target name=”php-codesniffer”>
<exec executable=”phpcs.bat” dir=”${basedir}/source”
output=”${basedir}/build/logs/checkstyle.xml”>
<arg line=”–report=checkstyle –standard=PEAR ./” />
</exec>
</target>
<target name=”phpmd”>
<exec executable=”phpmd.bat” dir=”${basedir}/source”>
<arg line=”./ xml codesize,unusedcode,naming” />
</exec>
</target>
<target name=”phpunit”>
<exec executable=”phpunit.bat” dir=”${basedir}/source”
failonerror=”on”>
<arg line=”–log-junit ${basedir}/build/logs/junit.xml –coverage-clover ${basedir}/build/logs/phpunit.coverage.xml –coverage-html ${basedir}/build/coverage phpucAllTests tests/AllTests.php” />
</exec>
</target>
<target name=”build”
depends=”checkout,php-documentor,php-codesniffer,phpmd,phpunit” />
</project>

Jenkins build.xml example which worked for me:

<project name=”Test Job” default=”build”>
<target name=”clean”>
<delete dir=”${basedir}/svn/_build”/>
<delete dir=”${basedir}/build”/>
</target>
<target name=”prepare”>
<mkdir dir=”${basedir}/svn/_build/logs”/>
<mkdir dir=”${basedir}/build/logs”/>
<mkdir dir=”${basedir}/build/docs”/>
</target>
<target name=”phpcpd”>
<exec dir=””
executable=”phpcpd.bat”
failonerror=”true”>
<arg line=”–log-pmd build/logs/pmd.xml ./”/>
</exec>
</target>
<target name=”pdepend”>
<exec dir=””
executable=”pdepend.bat”
failonerror=”true”>
<arg line=”–jdepend-xml=build/logs/jdepend.xml ./”/>
</exec>
</target>
<target name=”phpunit”>
<exec dir=””
executable=”phpunit.bat”
failonerror=”true”>
<arg line=”–log-junit _build/logs/junit.xml –coverage-clover build/logs/clover.xml phpucAllTests tests/AllTests.php”/>
</exec>
</target>
<target name=”code-coverage”>
<exec dir=””
executable=”phpunit.bat”
failonerror=”true”>
<arg line=”–coverage-html C:\xampp\htdocs\coverage phpucAllTests tests/AllTests.php”/>
</exec>
</target>
<target name=”phpdoc”>
<exec dir=””
executable=”phpdoc.bat”
failonerror=”true”>
<arg line=”-t build/docs/
–directory ./
-ti ‘Test Job Docs’
–parseprivate on
–undocumentedelements on
–output HTML:Smarty:PHP”/>
</exec>
</target>
<target name=”phpcs”>
<exec dir=””
executable=”phpcs.bat”
output=”build/logs/checkstyle.xml”
failonerror=”false”>
<arg line=”–report=checkstyle ./”/>
</exec>
</target>
<target name=”build” depends=”clean,prepare,phpcpd,pdepend,phpunit,code-coverage,phpdoc”/>
</project>

To install prerequisites I recommend installing latest XAMPP 1.7.4 because it has already some stuff preinstalled for You.

Advertisements