Setting up Jenkins with Github

11 Mar 2011 by Martin Vium

I just spend a lot more time cloning from github in Jenkins CI than was necessary.

After installing Jenkins, I started with Sebastian Bergmann's excellent php template for Jenkins was pretty straightforward and very well documented.

Cloning from Github

My first problem was with cloning my GitHub repository. I spend some time setting up ssh keys for authentication with Github. Now the easiest way would have been, to simply clone via the read-only url, as you therefore do not have to configure ssh.

Pick the right branch

After successfully cloning from Github, I kept getting some odd content. It turned out that it came from the gh-pages branch (wiki), that Github creates for you. Jenkins by default clones all the branches, one after another (look for ** in the configuration). Simply specifying the Branch Specifier as "master" fixed the problem.

Running the test suite

Lastly i had some trouble running the test suite. Console contained PHPUnit --help output, which basically means it doesn't know where the tests are. This is because, the template searches in the workspace root, instead of the tests folder. The solution was to add an argument, with the tests configuration file.

<target name="phpunit">
  <exec executable="phpunit" failonerror="true">
    <arg line="--configuration ${source}/tests/phpunit.xml ${source}/tests"/>
  </exec>
</target>

Missing coverage output

When the tests were running, Jenkins had trouble finding some xml files (build/logs/clover.xml and the build/coverage directory was empty). The php template for Jenkins recommends some logging options in phpunit.xml to generate these. However the logging methods that require Xdebug do not get executed without the extension. PHPUnit does not notify about this, but installing Xdebug fixed the problem.

Now everything is running smoothly, huzzah!