Top Topic ?

PHP and Hudson

Posted in php by Ladislav Prskavec on February 26, 2009

Hudson is extensible continuous integration engine used for Java projects. It’s architecture can be used for others languages as PHP too.

Install

  1. download war file
  2. run direct in console java -jar hudson.war (free port 8080 andJDK 1.5+)
  3. or make install to servlet server (Tomcat, Jetty, JBoss, …)
  4. after that go http://localhost:8080
  5. 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/

About these ads

16 Responses

Subscribe to comments with RSS.

  1. senjy said, on April 16, 2009 at 5:35 pm

    Why you don’t use , phing targets for build (with plugin install) instead of execute shell ?

  2. abtris said, on April 17, 2009 at 7:26 am

    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.

  3. stefan riedel said, on May 15, 2009 at 4:36 pm

    Hy, a very nice tool and realy simpler than “phpundercontrol”.

  4. Ian said, on July 16, 2009 at 9:30 am

    Thank you for this guide. Great help for hudson beginners like me.

  5. baptiste said, on July 28, 2009 at 10:52 am

    How do you handle the slightly different format between phpunit and clover/junit ?

    • Ladislav Prskavec said, on July 28, 2009 at 10:56 am

      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

  6. Dave said, on September 1, 2009 at 4:40 pm

    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.

    • Ladislav Prskavec said, on September 2, 2009 at 7:30 am

      I use two jobs, one per documentation and another per others. There are identical, I change only target in ant.

  7. […] Prskavec has posted a step-by-step guide on getting Hudson (a Java-based continuous integration server) working with PHP. Hudson is […]

  8. Hudson and PHP Howto at gog's info said, on November 6, 2009 at 7:38 pm

    […] 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 […]

  9. David Gardner: Page not found said, on November 9, 2009 at 1:44 pm

    […] 3 day agoPHP and Hudson " Top Topic ? […]

  10. Anirudh Zala said, on May 20, 2010 at 6:15 am

    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?

  11. […] 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 […]

  12. […] the other languages, it supported PHP. This article presents some nice plugins for PHP. The article is also suggesting Phing for the build. See […]

  13. […] the other languages, it supported PHP. This article presents some nice plugins for PHP. The article is also suggesting Phing for the build. See […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: