Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
[A.] Scripts related to Jenkins client setup
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
# As root ( via `sudo su -` ):
# Initialize ephemeral storage
curl > /etc/init.d/ephemeral
chmod +x /etc/init.d/ephemeral
ln -s ../init.d/ephemeral /etc/rcS.d/S10ephemeral
ln -s /mnt/jenkins /var/jenkins
ln -s /mnt/mongodb /var/lib/mongodb
ln -s /mnt/tmp /tmp
# Set logrotate to keep only one unit (day or week) of each log
for f in /etc/logrotate.d/* /etc/logrotate.conf ; do
sed -i 's/rotate [0-9]*$/rotate 1/' $f
apt-get update
apt-get install -y git build-essential bison openssl libreadline5 libreadline-dev curl git-core zlib1g zlib1g-dev libssl-dev libreadline-dev libxml2-dev autoconf libxslt-dev xvfb libgl1-mesa-dri xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic libyaml-dev
# Jenkins spot request setup
apt-get install -y openjdk-7-jre wget python
# Set up Xvfb (virtual framebuffer)
curl > /etc/init.d/xvfb
chmod +x /etc/init.d/xvfb
update-rc.d xvfb defaults
service xvfb start
apt-get install -y openjdk-6-jdk ant
apt-get install -y imagemagick libmagick9-dev
# Firefox setup (install dependencies, then uninstall to downgrade)
apt-get install -y firefox
apt-get remove -y firefox firefox-globalmenu
wget -O /tmp/firefox.tar.bz2
cd /usr/local
tar xjf /tmp/firefox.tar.bz2
cd bin
ln -s ../firefox/firefox .
ln -s ../firefox/firefox-bin .
# Set up MongoDB
curl >> /etc/apt/sources.list
apt-key adv --keyserver --recv 7F0CEB10
apt-get update
apt-get install -y mongodb-10gen
update-rc.d mongodb defaults
service mongodb start
# Set up Jenkins spot instance callbacks
curl >> /usr/local/bin/
chmod +x /usr/local/bin/
sed -i 's/^exit 0$/sudo -i -u jenkins python \/usr\/local\/bin\/\n&/' /etc/rc.local
# Set up Redis
apt-get install -y redis-server
# User-level setup
useradd -k /etc/skel -m -s /bin/bash jenkins
mkdir /home/jenkins/.ssh
cp /home/ubuntu/.ssh/authorized_keys /home/jenkins/.ssh/authorized_keys
chown -R jenkins:jenkins /home/jenkins/.ssh
chmod 700 /home/jenkins/.ssh
chmod 600 /home/jenkins/.ssh/authorized_keys
curl >> /etc/sudoers
groupadd wheel
usermod -G wheel jenkins
mkdir -p /var/jenkins/workspace
chown -R jenkins:jenkins /var/jenkins
# As user jenkins ( via `sudo su - jenkins` ):
sudo su -l jenkins
ssh-keygen -q -t rsa -N "" -f .ssh/id_rsa
curl -L | bash -s stable
rvm install 1.9.2
rvm install 1.9.3
rvm install 2.0.0
rvm install jruby --1.9
git clone git:// ~/.nvm
curl > /home/jenkins/.bash_login
mv /home/jenkins/.bashrc /home/jenkins/.bashrc~
curl > /home/jenkins/.bashrc
cat /home/jenkins/.bashrc~ >> /home/jenkins/.bashrc
rm /home/jenkins/.bashrc~
nvm install v0.8.17
curl >> /home/jenkins/.ssh/config
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
. ~/.nvm/
if [ -z "$PS1" ]; then
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
# Initialize ephemeral storage on /mnt
mkdir -p /mnt/jenkins/workspace
chown -R jenkins:jenkins /mnt/jenkins
mkdir -p /mnt/mongodb
chown mongodb:mongodb /mnt/mongodb
mkdir -p /mnt/tmp
chmod 1777 /mnt/tmp
import os
import httplib
import string
import base64
conn = httplib.HTTPConnection("")
conn.request("GET", "/latest/user-data")
response = conn.getresponse()
userdata =
args = string.split(userdata, "&")
jenkinsUrl = ""
jenkinsAuth = ""
slaveName = ""
for arg in args:
if arg.split("=")[0] == "JENKINS_URL":
jenkinsUrl = arg.split("=")[1]
if arg.split("=", 1)[0] == "USER_DATA":
subarg = base64.b64decode(arg.split("=", 1)[1])
if subarg.split("=")[0] == "JENKINS_AUTH":
jenkinsAuth = subarg.split("=")[1]
if arg.split("=")[0] == "SLAVE_NAME":
slaveName = arg.split("=")[1]
os.system("wget " + jenkinsUrl + "jnlpJars/slave.jar -O slave.jar")
os.system("java -jar slave.jar -jnlpCredentials " + jenkinsAuth + " -jnlpUrl " + jenkinsUrl + "computer/" + slaveName + "/slave-agent.jnlp")
# 10gen MongoDB repository
deb dist 10gen
StrictHostKeyChecking no
StrictHostKeyChecking no
Host *
ServerAliveInterval 15
XVFBARGS=":99 -screen 0 1024x768x24 -fbdir /var/run -ac"
case "$1" in
echo -n "Starting virtual X frame buffer: Xvfb"
start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS
echo "."
echo -n "Stopping virtual X frame buffer: Xvfb"
start-stop-daemon --stop --quiet --pidfile $PIDFILE
echo "."
$0 stop
$0 start
echo "Usage: /etc/init.d/xvfb {start|stop|restart}"
exit 1
exit 0
Copy link

This script is intended primarily for informational purposes, and as a base for similar custom configuration scripts. Setup instructions for nihilists and other reckless individuals:

  1. Launch Ubuntu 11.10 AMI 4dad7424.
  2. Log in to the instance, and run the following commands:
curl -L | sudo bash -s
sudo su -l jenkins
curl -L | bash -s

Copy link

Cross ref; This post 2012-07 describes Artsy's use of these setup scripts;

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