PHP and Hudson
Hudson is extensible continuous integration engine used for Java projects. It’s architecture can be used for others languages as PHP too.
Install
- download war file
- run direct in console java -jar hudson.war (free port 8080 andJDK 1.5+)
- or make install to servlet server (Tomcat, Jetty, JBoss, …)
- after that go http://localhost:8080
- plugins recommended for php
Build
For build can use phing (example) or ant.
<?xml version="1.0" encoding="UTF-8"?> <project name="start_page" basedir="." default="main"> <!-- $Id: build.xml 102 2009-02-26 14:39:10Z abtris $ --> <property name="tmp" value="/tmp" /> <property name="wsname" value="source" /> <property name="package" value="${phing.project.name}" override="true" /> <property name="builddir" value="${tmp}/build/${phing.project.name}" override="true" /> <property name="srcdir" value="./src/" override="true" /> <!-- Main Target --> <target name="main" description="main target"> <!-- Create dirs --> <mkdir dir="${builddir}/reports"/> <mkdir dir="${builddir}/reports/coverage"/> <!-- PHP API Documentation --> <phpdoc title="API Documentation" destdir="${builddir}/apidocs" sourcecode="yes" defaultpackagename="StartPage" output="HTML:Smarty:PHP"> <fileset dir="."> <include name="*/*.php" /> </fileset> </phpdoc> <!-- PHP CodeSniffer --> <exec command="phpcs --standard=ZEND --report=checkstyle ${ws}/${wsname}/src/ > ${builddir}/reports/checkstyle.xml" escape="false" /> <!-- PHPUnit --> <exec command="phpunit --log-xml ${builddir}/reports/phpunit.xml --log-pmd ${builddir}/reports/phpunit.pmd.xml --coverage-clover ${builddir}/reports/coverage/clover.xml --coverage-html ${builddir}/reports/coverage/ tests/AllTests.php"/> </target> </project>
Example configuration
Project name: StartPage
Source Code Management: Subversion
Repository URL: https://localhost/svn/start_page/trunk
Local module directory (optional): source
Use update: true
Build
Execute shell: phing -f $WORKSPACE/source/build.xml -Dws=$WORKSPACE -Dtmp=$WORKSPACE
Post-build action
Publish Javadoc
Javadoc directory = build/start_page/apidocs/
Retain javadoc for each successful build = false
Publish JUnit test result report
Test report XMLs = build/start_page/reports/phpunit.xml
Publish Checkstyle analysis results
Checkstyle results = build/start_page/reports/checkstyle.xml
Publish PMD analysis results
PMD results = build/start_page/reports/phpunit.pmd.xml
Publish Clover Coverage Report
Clover report directory = build/start_page/reports/coverage/
Why you don’t use , phing targets for build (with plugin install) instead of execute shell ?
I don’t use phing plugin. I prefered using Ant. I use Ant for building RPM packages and generate phpdoc, tests etc. For Ant is better support in Eclipse and i can use them for Java applications too.
Hy, a very nice tool and realy simpler than “phpundercontrol”.
Thank you for this guide. Great help for hudson beginners like me.
How do you handle the slightly different format between phpunit and clover/junit ?
I use this shell commands:
lines=`wc -l $WORKSPACE/build/logs/phpunit.xml|awk '{print $1}'`
end=`expr $lines - 1`
sed -i "$end d;3d" $WORKSPACE/build/logs/phpunit.xml
or
xUnit plugin
Thanks for the great tutorial. There’s a new plugin, xUnit, that supports reformatting the PHPUnit (and many others) xml for you.
I have an issue that maybe you could help me with.
Is there a way to toggle whether or not the Javadoc is published? In my application it takes 15 minutes just to generate the phpdocs. This is something I don’t need to have happen every time, as my unit tests themselves take < 5 minutes. I've configured a build parameter for my builds that specifies the build target for phing. I use lite / full to designate whether to include phpdoc or not. However, whenever I run a lite build, Hudson marks it as failed because there is no Javadoc to publish.
I tried disabling the javadoc publishing, but that also removes the Documentation link for the entire job.
Any ideas? Thanks in advance.
I use two jobs, one per documentation and another per others. There are identical, I change only target in ant.
[…] Prskavec has posted a step-by-step guide on getting Hudson (a Java-based continuous integration server) working with PHP. Hudson is […]
[…] found a quite nice tutorial about setting up Hudson with PHP here but I had some questions marks hovering over my head during the installation so I have decided to […]
[…] 3 day agoPHP and Hudson " Top Topic ? […]
In latest version of Hudson 1.358 (and maybe earlier) code coverage doesn’t work when you publish Javadoc and Clover coverage doc in same job. Can you check this?
[…] https://toptopic.wordpress.com/2009/02/26/php-and-hudson/ […]
[…] Bergmann's php-hudson-template, but there are also other good articles: Ladislav Prskavec's PHP and Hudson, and Goran Juri?'s Hudson on Debian […]
[…] the other languages, it supported PHP. This article presents some nice plugins for PHP. The article is also suggesting Phing for the build. See […]
[…] the other languages, it supported PHP. This article presents some nice plugins for PHP. The article is also suggesting Phing for the build. See […]