blob: e0e774ee9ead4699674808215bfc1ae3b4e34e34 [file] [log] [blame]
Anthony Young43acae42011-11-08 14:23:56 -08001#!/bin/bash
2
3# Echo commands, exit on error
4set -o xtrace
5set -o errexit
6
7# Make sure only root can run our script
8if [[ $EUID -ne 0 ]]; then
9 echo "This script must be run as root"
10 exit 1
11fi
12
13# This directory
14CUR_DIR=$(cd $(dirname "$0") && pwd)
15
Anthony Young723e2d22011-11-11 13:42:09 -080016# Configure trunk jenkins!
17echo "deb http://pkg.jenkins-ci.org/debian binary/" > /etc/apt/sources.list.d/jenkins.list
18wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
19apt-get update
20
Anthony Young57346b72011-11-11 13:53:56 -080021
22# Clean out old jenkins - useful if you are having issues upgrading
23CLEAN_JENKINS=${CLEAN_JENKINS:-no}
Anthony Young5dbfdea2011-11-14 12:40:04 -080024if [ "$CLEAN_JENKINS" = "yes" ]; then
Anthony Young57346b72011-11-11 13:53:56 -080025 apt-get remove jenkins jenkins-common
26fi
27
Anthony Young43acae42011-11-08 14:23:56 -080028# Install software
Anthony Youngc18af142011-11-09 12:20:37 -080029DEPS="jenkins cloud-utils"
Anthony Young43acae42011-11-08 14:23:56 -080030apt-get install -y --force-yes $DEPS
31
32# Install jenkins
33if [ ! -e /var/lib/jenkins ]; then
34 echo "Jenkins installation failed"
35 exit 1
36fi
37
Anthony Young977b3342011-11-15 13:30:20 -080038# Make sure user has configured a jenkins ssh pubkey
39if [ ! -e /var/lib/jenkins/.ssh/id_rsa.pub ]; then
40 echo "Public key for jenkins is missing. This is used to ssh into your instances."
41 echo "Please run "su -c ssh-keygen jenkins" before proceeding"
42 exit 1
43fi
44
Anthony Young43acae42011-11-08 14:23:56 -080045# Setup sudo
46JENKINS_SUDO=/etc/sudoers.d/jenkins
47cat > $JENKINS_SUDO <<EOF
48jenkins ALL = NOPASSWD: ALL
49EOF
50chmod 440 $JENKINS_SUDO
51
52# Setup .gitconfig
53JENKINS_GITCONF=/var/lib/jenkins/hudson.plugins.git.GitSCM.xml
54cat > $JENKINS_GITCONF <<EOF
55<?xml version='1.0' encoding='UTF-8'?>
56<hudson.plugins.git.GitSCM_-DescriptorImpl>
57 <generation>4</generation>
58 <globalConfigName>Jenkins</globalConfigName>
59 <globalConfigEmail>jenkins@rcb.me</globalConfigEmail>
60</hudson.plugins.git.GitSCM_-DescriptorImpl>
61EOF
62
Anthony Youngec67f1e2011-11-09 17:46:28 -080063# Add build numbers
Anthony Young5df68182011-11-10 09:56:12 -080064JOBS=`ls jobs`
65for job in ${JOBS// / }; do
Anthony Youngec67f1e2011-11-09 17:46:28 -080066 if [ ! -e jobs/$job/nextBuildNumber ]; then
67 echo 1 > jobs/$job/nextBuildNumber
68 fi
69done
70
Anthony Young43acae42011-11-08 14:23:56 -080071# Set ownership to jenkins
72chown -R jenkins $CUR_DIR
73
Anthony Young316117a2011-11-09 11:10:26 -080074# Make sure this directory is accessible to jenkins
75if ! su -c "ls $CUR_DIR" jenkins; then
76 echo "Your devstack directory is not accessible by jenkins."
77 echo "There is a decent chance you are trying to run this from a directory in /root."
78 echo "If so, try moving devstack elsewhere (eg. /opt/devstack)."
79 exit 1
80fi
81
Anthony Young48336d02011-11-09 11:12:14 -080082# Move aside old jobs, if present
Anthony Young43acae42011-11-08 14:23:56 -080083if [ ! -h /var/lib/jenkins/jobs ]; then
84 echo "Installing jobs symlink"
85 if [ -d /var/lib/jenkins/jobs ]; then
86 mv /var/lib/jenkins/jobs /var/lib/jenkins/jobs.old
87 fi
Anthony Young43acae42011-11-08 14:23:56 -080088fi
89
Anthony Young48336d02011-11-09 11:12:14 -080090# Set up jobs symlink
91rm -f /var/lib/jenkins/jobs
92ln -s $CUR_DIR/jobs /var/lib/jenkins/jobs
93
Anthony Young43acae42011-11-08 14:23:56 -080094# List of plugins
95PLUGINS=http://hudson-ci.org/downloads/plugins/build-timeout/1.6/build-timeout.hpi,http://mirrors.jenkins-ci.org/plugins/git/1.1.12/git.hpi,http://hudson-ci.org/downloads/plugins/global-build-stats/1.2/global-build-stats.hpi,http://hudson-ci.org/downloads/plugins/greenballs/1.10/greenballs.hpi,http://download.hudson-labs.org/plugins/console-column-plugin/1.0/console-column-plugin.hpi
96
97# Configure plugins
98for plugin in ${PLUGINS//,/ }; do
99 name=`basename $plugin`
100 dest=/var/lib/jenkins/plugins/$name
101 if [ ! -e $dest ]; then
102 curl -L $plugin -o $dest
103 fi
104done
105
106# Restart jenkins
Anthony Youngc0d4e672011-11-11 13:46:44 -0800107/etc/init.d/jenkins stop || true
108/etc/init.d/jenkins start