public
Last active

A bash script to set up Quickstart as a continuous integration appliance.

  • Download Gist
install-citools.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
#!/bin/bash
 
# Follow the steps below to configure Quickstart as a continuous integration appliance, complete with Jenkins,
# Selenium Builder, Selenium Server, PHPUnit, and Selenium Zoetrope. The script also configures and runs an
# example Jenkins test job for Quickstart's example6.dev site, including Simpletest module testing and
# Coder module checks.
#
# 1. Download Quickstart and follow the installation instructions:
# http://drupal.org/project/quickstart
# 2. Open a Terminal window (Applications > Accessories > Terminal) and run the following command:
# $ wget -q -O - https://raw.github.com/gist/1306186/install-citools.sh | bash
# 3. As the script runs, read and follow the directions that appear in the pop-up boxes.
# 4. When the script completes, Jenkins should open in Firefox. If not, enter the following URL in Firefox:
# http://localhost:8081
# 5. Add a variable (Manage Jenkins > Configure System > check Environment variables > click Add)
# name: DISPLAY
# value: :0.0
 
jenkins_check() {
rc=1
while [ $rc -ne 0 ]; do
sleep 5
wget --spider http://localhost:8081 > /dev/null 2>&1
rc=$?
done
}
 
echo "###############################################"
echo "Removing mis-configured local proxy"
echo "###############################################"
# For more info: http://drupal.org/node/1194150
sudo sed -i '/http_proxy.*/d' /etc/environment
unset http_proxy
 
echo "###############################################"
echo "Updating Firefox"
echo "###############################################"
sudo add-apt-repository ppa:mozillateam/firefox-stable
sudo apt-get update
echo "y" | sudo apt-get install firefox
 
echo "###############################################"
echo "Installing Selenium Builder"
echo "###############################################"
wget -O /tmp/se-builder.xpi https://addons.mozilla.org/firefox/downloads/latest/285515/addon-285515-latest.xpi
firefox /tmp/se-builder.xpi &
sleep 12
zenity --info --text="Firefox will start.\n\n1) Please accept the installation of the Selenium Builder extension.\n2) Then restart Firefox." &
 
echo "###############################################"
echo "Installing Simpletest & tools to example6.dev"
echo "###############################################"
cd /home/quickstart/websites/example6.dev/
drush dl -l http://example6.dev/ simpletest
# Apply patch file required to run tests in Drupal 6
patch -p0 < sites/all/modules/simpletest/D6-core-simpletest.patch
drush -y -l http://example6.dev/ en simpletest
# Use pre-patched run-tests.sh script bundled with Pressflow
cd /home/quickstart/websites/example6.dev/scripts/
wget https://raw.github.com/pressflow/6/master/scripts/run-tests.sh
 
echo "###############################################"
echo "Installing Coder module on example6.dev"
echo "###############################################"
cd /home/quickstart/websites/example6.dev/
# Use -dev version because of checkstyle additions
# For more info: http://drupal.org/node/858330#comment-4876440
drush dl -l http://example6.dev/ coder-6.x-2.x-dev
drush -y -l http://example6.dev/ en coder
 
echo "###############################################"
echo "Installing Selenium Server"
echo "###############################################"
mkdir /home/quickstart/selenium-server-2.15.0/
wget -O /home/quickstart/selenium-server-2.15.0/selenium-server.jar http://selenium.googlecode.com/files/selenium-server-standalone-2.15.0.jar
 
echo "###############################################"
echo "Installing Selenium Zoetrope dependencies"
echo "###############################################"
echo "y" | sudo apt-get install xvfb
echo "y" | sudo apt-get install ffmpeg
sudo pear upgrade PEAR
sudo pear channel-update pear.php.net
sudo pear config-set auto_discover 1
sudo pear install pear.phpunit.de/PHPUnit
sudo pear install phpunit/PHPUnit_Selenium
 
echo "###############################################"
echo "Installing Selenium Zoetrope"
echo "###############################################"
# For more info: https://launchpad.net/selenium-zoetrope
cd /home/quickstart/
bzr branch lp:selenium-zoetrope
 
echo "###############################################"
echo "Running separate Jenkins installation script"
echo "###############################################"
# For more info: http://drupal.org/node/1301862
cd /home/quickstart/
git clone git://gist.github.com/1477667.git
cp 1477667/install-jenkins.sh /home/quickstart/quickstart/contrib/
chmod 755 /home/quickstart/quickstart/contrib/install-jenkins.sh
rm -rf 1477667/
echo "y" | . /home/quickstart/quickstart/contrib/install-jenkins.sh
 
echo "###############################################"
echo "Installing Jenkins plugins"
echo "###############################################"
# Give Jenkins time to start up
jenkins_check
# Manually run Updatecenter
# For more info: https://gist.github.com/1026918
wget -O default.js http://updates.jenkins-ci.org/update-center.json
sed '1d;$d' default.js > default.json
curl -X POST -H "Accept: application/json" -d @default.json http://localhost:8081/updateCenter/byId/default/postBack --verbose
java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -s http://localhost:8081 install-plugin xunit
java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -s http://localhost:8081 install-plugin git
java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -s http://localhost:8081 install-plugin checkstyle
 
echo "###############################################"
echo "Adding Jenkins job"
echo "###############################################"
cd /home/quickstart/jenkins/jobs/
git clone git://git.assembla.com/ex6devtest.git
# Restart so jobs get loaded
java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -s http://localhost:8081 safe-restart
# Give Jenkins time to restart
jenkins_check
wget http://localhost:8081/job/ex6devtest/buildWithParameters -o /dev/null
while [ ! -e /home/quickstart/jenkins/jobs/ex6devtest/workspace/test-results ]
do
printf "."
sleep 1
done
cd /home/quickstart/jenkins/jobs/ex6devtest/
# Jenkins wipes out the job's workspace directory when first run, so we need to recover the necessary subdirectories
git checkout -- workspace/selenium/.
 
echo "###############################################"
echo "Loading Jenkins interface in Firefox"
echo "###############################################"
firefox http://localhost:8081 &

There's no way this will work:

sed -e "/http_proxy.*/d" /etc/environment | sudo tee /etc/environment

When the shell creates a pipeline, it must start the processes from the right end of the pipeline. In this case, it would first run "tee /etc/environment", which truncates the file. Then the shell will run the sed command that reads from the truncated file. Of course, if sed starts up faster than tee can truncate the file, it might work, sometimes.

Consider using the -i option of sed to edit files in place.

@stisti Thanks for the tip! I've now updated the script.

@mvance thanks very much for sharing this. This has been really useful and has saved me hours of strife!

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.