Skip to content

Instantly share code, notes, and snippets.

@mvance
Created October 22, 2011 16:40
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvance/1306186 to your computer and use it in GitHub Desktop.
Save mvance/1306186 to your computer and use it in GitHub Desktop.
A bash script to set up Quickstart as a continuous integration appliance.
#!/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 &
@stisti
Copy link

stisti commented Dec 9, 2011

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.

@mvance
Copy link
Author

mvance commented Dec 9, 2011

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

@michael38autumn
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment