Jenkins & The Continuous Integration Game

Jeff Atwood writes about The Gamification and he states that there is “… a long, rich history of programmers as gamers“. He writes that programmers want “…to move beyond being a mere player and change the game, control it, modify its parameters, maybe even create our own games.”

Sure, but even when this is not true I believe that most people enjoy to compete in a game like fashion. We see this happen at the supermarket where we can tag reduction stickers on products and where we can collect trophies when we shop enough (often aimed at kids, but enjoyed by a broad public).

Recently I ran into “ci-game” or as it is fully called “The Continuous Integration Game”. It is a plugin for Jenkins that allows comitters to compete and collect points by improving the code in the repository. It requires that you have set up Jenkins to autmatically build you project(s). When a user commits code, the change is evaluated by the plugin. The plugin calculates an amount of points, either positive or negative and that is added to the comitters current score.

Since we use a lot of PHP and the game was designed for Java it was a bit of a challenge to get it working. We installed jenkins from the Ubuntu 12.04 repository. After installing Jenkins we installed the required plugins. After that we set up the Template for Jenkins Jobs for PHP Projects. Then we upgraded Jenkins from within Jenkins itself. After that we installed the ci-game plugin. Everything works and we are enjoying some healthy competition in the office.

Rules

The rules of the game are:

  • -10 points for breaking a build
  • 0 points for breaking a build that already was broken
  • +1 points for doing a build with no failures (unstable builds gives no points)
  • -1 points for each new test failures
  • +1 points for each new test that passes

Rules that depend on other plugins (and are therefor optional):

  • PMD Plugin. Adding/removing a HIGH priority warning = -5/+5. Adding/removing a MEDIUM priority warning = -3/+3. Adding/removing a LOW priority warning = -1/+1.
  • Task Scanner Plugin. Adding/removing a HIGH priority task = -5/+5. Adding/removing a MEDIUM priority task = -3/+3. Adding/removing a LOW priority task = -1/+1
  • Violations Plugin. Adding/removing a violation = -1/+1. Adding/removing a duplication violation = -5/+5.
  • FindBugs Plugin. Adding/removing a HIGH priority findbugs warning = -5/+5. Adding/removing a MEDIUM priority findbugs warning = -3/+3. Adding/removing a LOW priority findbugs warning = -1/+1
  • Warnings Plugin. Adding/removing a compiler warning = -1/+1.
  • Checkstyle Plugin. Adding/removing a checkstyle warning = -1/+1.
Share

Continuous Integration for Symfony2 using Jenkins

Today I will show how to set up Continuous Integration (CI) for Symfony2 using Jenkins and the PHP-template for Jenkins jobs by Sebastian Bergmann.

This configuration works successfully with Symfony ver. 2.1 and Jenkins ver. 1.480.1.

Installing requirements

Before creating template jobs you need to install the Required Jenkins Plugins and Required PHP Tools.

Using the Symfony2 PHP Jenkins job template

I based the first steps on http://jenkins-php.org/, but I will use config.xml, build.xml, phpunit.xml and additional files from this website: https://github.com/xurumelous/symfony2-jenkins-template.

  1. Fetch the jenkins-cli.jar from your Jenkins server
    wget http://localhost:8080/jnlpJars/jenkins-cli.jar
  2. Download and install the job template
    curl https://github.com/xurumelous/symfony2-jenkins-template/blob/master/config.xml | \
    java -jar jenkins-cli.jar -s http://localhost:8080/jenkins create-job symfony2-php-template

    or add the template manually:

    cd $JENKINS_HOME/jobs
    mkdir symfony2-php-template
    cd symfony2-php-template
    wget https://github.com/xurumelous/symfony2-jenkins-template/blob/master/config.xml
    cd ..
    chown -R jenkins:jenkins symfony2-php-template/
  3. Reload Jenkins’ configuration, for instance using the Jenkins CLI:
    java -jar jenkins-cli.jar -s http://localhost:8080 reload-configuration
  4. Click on “New Job”
  5. Enter the “Job name”
  6. Select “Copy existing job” and enter “symfony2-php-template” into the “Copy from” field.
  7. Click “OK”
  8. Configure your new job with version control and whatever other fields you need.

Project configuring and issues fixing

  1. Make changes from the basic Jenkins-PHP config to Symfony2-Jenkins-PHP as described here: https://github.com/xurumelous/symfony2-jenkins-template
    • Move the Jenkins folder to [SYMFONY2_ROOT]/app/Resources/ inside your Symfony2 project
    • Move build.xml to the root folder of your Symfony2 application
    • Move phpunit.xml to [SYMFONY2_ROOT]/app folder or update the existing one. The logging node is needed!
  2. If you get the following message: PHP Fatal error:  Class ‘XSLTProcessor’ not found in /usr/share/php/TheSeer/fXSL/fxsltprocessor.php on line 58, you can fix  it with 
    sudo apt-get install php5-xsl
  3. You might also get this error message, because we run Symfony 2.1, which needs a composer: PHP Warning:  require(/var/lib/jenkins/jobs/TestJob/workspace/app/../vendor/autoload.php): failed to open stream: No such file or directory in /var/lib/jenkins/jobs/TestJob/workspace/app/autoload.php on line 5 . You can fix this problem like this:
  4. Sometimes you encounter a problem on the “vendors” step, saying something like this:

    [exec] The deps file is not valid ini syntax. Perhaps missing a trailing newline?
    [exec] PHP Warning:  parse_ini_file(/var/lib/jenkins/jobs/TestJob/workspace/deps): failed to open stream: No such file or directory in  /var/lib/jenkins/jobs/TestJob/workspace/bin/vendors on line 69

    You can fix this by removing “vendors” from build dependency and the “vendors” target in build.xml

  5. If you get a Status: 2 during the codesniffer step (phpcs) you need to install Symfony2 coding standard https://github.com/opensky/Symfony2-coding-standard
  6. Enable checkbox “Poll SCM” and write: */5 * * * * (This step makes Jenkins check every 5 minutes if there are changes in the repository. If any changes are found, it will automatically build a project)

That’s it! You are now ready to build your PHP Symfony2 project with Jenkins! If you find bugs (or fixes), links, or have other suggestions, do not hesitate to comment below.

Enjoy the result!

Share