Continuous integration with cijoe and PHP

2 minutters læsning

Because knowing is half the battle, I looked into some possibilites for setting up a continuous integration server with my php projects hosted in github repositories. I wanted it to be easy, and I found cijoe. The server is easy to setup, but also has very few features.

Setting it up

I read through the docs and A Guide to Simplified Automated Drupal Testing and I had it set up in practically no time. The latter article explains how to setup Ruby and Rubygems on Ubuntu. The latter article also shows how to put cijoe in the path, so you can access it directly from the commandline.

Making it work

I want the tests to run when something is commited. I started off with my small project PHP Exif Library.

First I cloned the repository:

git clone git://

Second, I made minor adjustments to my test script, so I could run it from the root of the library.

Third, I setup a cijoe.runner which is run when every build. Being new to git config, it just copied and pasted this from the cijoe documentation (replacing the command with my own) and executed it from the root of the cloned repository:

git config --add cijoe.runner "php test/run-tests.php"

Fourth, I started cijoe by the following command:

cijoe pel

Fire up the browser http://localhost:4567

Hit build. Reload the browser. And you can se cijoe at work. And maybe help fix the two failing tests.

What is next?

  • Invoke builds on commits. cijoe does not automatically listen for changes in the repository. However, reading through the docs you can see how to add a post-receive hook to github. To invoke a build just make a POST request for cijoe browser address.
  • Get notified. Make hook scripts at get notified about the result of the build. The hook scripts are just shell scripts, so you can do whatever you want. You might want to use notifo for that? I used curl to post the message. Just need to figure out which variables I can use, so I can make the notification more precise.
#!/usr/bin/env bash
# Note the use of env. This is because executables may not be placed in the same place on all systems. Notoriously, bsd (and thus mac osx) differs from linux. However, /usr/bin/env always exists in the same place, and it can tell you where other executables are. Thus, the above is good style for portability.

COMMIT_VERSION=$(git rev-parse --verify HEAD)
COMMIT_LOG=$(git log -n 1)
# You could also use backticks, but the $() syntax is generally more readable
# Convention is to put variables in uppercase in shell script
LOG="$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "${COMMIT_LOG}")"

curl -k -u user:password \
    -d "to=lsolesen&msg=${LOG}&title=Intraface+build+failed&${COMMIT_VERSION}" \ > /dev/null
# You can embed a variable in a string, using the ${VAR_NAME} syntax

The caveats

cijoe is simple. If you need more features, you should look for another continuous integration server.

  • Want more instances in one browser. I have a lot of projects, and even though I can run multiple instances of cijoe on different port, it would be nice having all the projects in one browser window. You might want to use buildboard for that.
  • I do not want to reload. Why do I have to reload the browser to see the result of the build.
  • No history. There is no history.

Never mind the caveats. cijoe is really easy to use. And the most important step in killing bugs, is knowing that they are there.