Drupal, Jenkins & testing - automating every phing
Introduction
This is a guide for setting up a Jenkins server on Ubuntu for the purposes of automating a Drupal 7 install and automated test process.
All commands assume you’re running Ubuntu 14.04 as root user (unless otherwise specified).
This was primarily put together to accompany a talk at Drupalcamp Brighton 2015.
Requirements:
Publicly accessible server (We'll use a digital ocean 1GB/1CPU droplet as it's super quick to setup!)
1GB+ RAM
a publicly accesible domain name (for testing)
Prepare the server
The are a number of standard security measures you should take when setting up any publicly accessible server which is beyond the scope of this demo. For more details see: https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-14-04
Create droplet - adding ssh key
ssh root@IP address
Install Jenkins
wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
apt-get update
apt-get install jenkins
service jenkins start
Install required packages
apt-get install php5 php5-cli php5-curl php5-gd sqlite3 libsqlite3-dev php5-sqlite mysql-server php5-mysql apache2 php-pear git zip nano
Whilst we’ll be managing most of our dependencies through composer rather than pear there’s at least one package that doesn’t play nicely with composer:
pear install HTTP_Request2
Install Composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
To test composer is sucessfully installed run:
composer
Configure Jenkins
Jenkins is installed on port 8080 by default and will be installed with no security parameters by default - there are several ways to secure a jenkins instance instructsion for which are covered in detail here: https://wiki.jenkins-ci.org/display/JENKINS/Securing+Jenkins
Visit your jenkins instance http://{SERVER_IP}:8080
Install the follwing plugins at http://{SERVER_IP}:8080/manage
Phing, PHP Plugin, Github plugin
Restart Jenkins Ensure WORKSPACE/bin is on jenkins user path
configure Environment variables at http://{SERVER_IP}:8080/configure - tick environment variables
name: PATH
value: $WORKSPACE/bin:$PATH
Ordering is important as first entries are executed first. Tell Jenkins where Phing will be
Configure phing installations at http://{SERVER_IP}:8080/configure - click Phing Installations
Phing Home: $WORKSPACE/vendor/phing/phing
Create a new job called “drupal-template” - load config from template (https://github.com/miggle/Migl-Phing-Drupal/tree/master/drupal-template)
su jenkins
cd /var/lib/jenkins/jobs
mkdir drupal-template
cd drupal-template
wget https://raw.githubusercontent.com/miggle/Migl-Phing-Drupal/master/drupal-template/config.xml
reload configuration from disk at http://{SERVER_IP}:8080/manage Build project - It will fail but required to create directories for next step!
Apache config - make jenkins workspace vhost accessible
Edit apache config
nano /etc/apache2/apache2.conf
Ensure the server has "AllowOverrides All"configured for the server document root.
Enable apache rewrite module
a2enmod rewrite
Adjust apache user to ensure it will have group write access to jenkins generated files.
Best way I've found to do this is to run the following:
id www-data
making a note of the group id
id jenkins
making a note of the group id
Then run the following replacing the 2 numbers in {} with the digits you noted down:
usermod -G {33},{114} www-data
Required step to allow webtest cases and Behat tests to function correctly.
Point a domain at the server ci.mydomain.co.uk
create a symlink in the apache root for your site
mkdir /var/www/vhosts
ln -s /var/lib/jenkins/jobs/drupal-template/workspace/docroot /var/www/vhosts/ci.mydomain.co.uk
Create an apache Vhost
cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/ci.mydomain.co.uk.conf
Edit the new host file
nano /etc/apache2/sites-available/ci.mydomain.co.uk.conf
Edit ServerName - enter your url e.g.. ci.mydomain.co.uk
Edit DocumentRoot - enter: /var/www/vhosts/ci.mydomain.co.uk
a2ensite ci.mydomain.co.uk.conf
apache2ctl -t
Review the output of the above and restart if all look good!
service apache2 restart
Run another build in Jenkins and review the results
Now when you run a build you should see the results of the tests start coming in! Now's your chance to start a fresh and get altering the code for your purposes. Have fun!















