Commands for installing Jenkins for a PHP project on Ubuntu 11.04 server with automatic pulling of code from private Github repository

I have not added many explanations in this article. Please see the sources I’ve used for better explanations of what’s happening, etc (see the bottom of the article). I mostly present the commands I executed during setup. Git is being used as source code management and the repository is located at a private Github repository. For a public repository just skip the part about generating SSH keys. Using a bunch of tools to analyze the code for each build. Jenkins will also run the unit/integration/acceptenace tests (PHPUnit / PHPUnit + Selenium) specified in phpunit.xml.

Installing Jenkins, PHP5, Xdebug, Ant, etc

sudo apt-get update
sudo apt-get install php5-cli php5-xdebug php-pear ant git
php -r 'echo "Xdebug loaded? "; echo (extension_loaded("xdebug")) ? "yes" : "no"; echo chr(10);'
wget -q -O - | sudo apt-key add -
sudo bash -c "echo 'deb binary/' > /etc/apt/sources.list.d/jenkins.list"
sudo apt-get update
sudo apt-get install jenkins

You can now load jenkins at http://localhost:8080/ (or http://ip.address:8080/)

Installing Jenkins plugins

wget http://localhost:8080/jnlpJars/jenkins-cli.jar
java -jar jenkins-cli.jar -s http://localhost:8080 install-plugin checkstyle
java -jar jenkins-cli.jar -s http://localhost:8080 install-plugin cloverphp
java -jar jenkins-cli.jar -s http://localhost:8080 install-plugin dry
java -jar jenkins-cli.jar -s http://localhost:8080 install-plugin htmlpublisher
java -jar jenkins-cli.jar -s http://localhost:8080 install-plugin jdepend
java -jar jenkins-cli.jar -s http://localhost:8080 install-plugin plot
java -jar jenkins-cli.jar -s http://localhost:8080 install-plugin pmd
java -jar jenkins-cli.jar -s http://localhost:8080 install-plugin violations
java -jar jenkins-cli.jar -s http://localhost:8080 install-plugin xunit
java -jar jenkins-cli.jar -s http://localhost:8080 install-plugin git
java -jar jenkins-cli.jar -s http://localhost:8080 safe-restart

Install PHPUnit and other PHP tools

sudo pear upgrade PEAR
sudo pear channel-discover
sudo pear channel-discover
sudo pear channel-discover
sudo pear channel-discover
sudo pear channel-discover
sudo pear install pdepend/PHP_Depend
sudo pear install phpmd/PHP_PMD
sudo pear install phpunit/phpcpd
sudo pear install phpunit/phploc
sudo pear install PHPDocumentor
sudo pear install PHP_CodeSniffer
sudo pear install --alldeps phpunit/PHP_CodeBrowser
sudo pear install --alldeps phpunit/PHPUnit

Add config files to your repository

I ended up with the following structure inside the repository for the project:

  • /build.xml
  • /build/phpcs.xml
  • /build/phpmd.xml
  • /tests/phpunit.xml
  • /tests/subfolders/abctest.php

Download job template for PHP

cd /var/lib/jenkins/jobs/
sudo git clone git:// php-template
sudo chown -R jenkins:nogroup php-template/
sudo /etc/init.d/jenkins stop
sudo /etc/init.d/jenkins start

Deploy key for Github

Since I use Jenkins against a private Github repository, I need a SSH key defined for the Jenkins user.

sudo -u jenkins ssh
sudo -u jenkins ssh-keygen
sudo cat ~jenkins/.ssh/
# Copy the key over to Github as a "Deploy key" under administration for the project
sudo -u jenkins ssh
# Last command should say that you are authenticated

Create a Jenkins job for your project

  • Go to your Jenkins web site: http://localhost:8080/ or replace localhost with the IP of the server
  • In menu: «Manage Jenkins»
  • Select «Manage plugins»
  • Select «Configure System»
  • Under «Git plugin» set user name and e-mail for Git (e.g. Jenkins and
  • In menu: «New Job»
  • Enter a project name
  • Select «Copy existing job» and type in «php-template» (the option to copy from an existing job is not available if php-template is not downloaded and properbly change owner of (chown))
  • Click «OK» to create the job. You’ll be sent to the edit job page
  • Uncheck «Disable build»
  • Under «Source Code Management», select «Git» as «Source Code Management»
  • Get your repository address from Github and put it in «URL of repository». Example:
  • Also specify branches to build if not all branches, including submodules, have a build.xml for Jenkins to read. Example: master
  • Under «Build triggers», enable «Poll SCM» and put «* * * * *» in Schedule for polling every minute
  • Click «Save»
  • Now click on «Build now» in the menu to the left
  • Click on the build and then console output to watch it check out your code, submodules of your Git project and run tests


Dette innlegget ble publisert i PHP, Ubuntu / Linux og merket med , , , , , , , , , . Bokmerk permalenken.

En kommentar til Commands for installing Jenkins for a PHP project on Ubuntu 11.04 server with automatic pulling of code from private Github repository

  1. Tilbaketråkk: Notes: PHP QA Tools + Jenkins PHP Project Template « David's Raging Nexus

Det er stengt for kommentarer.