blob: 9a32a0a1fa559de8c345b151a2f992f5e59593d1 [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
Anthony Youngb2256822011-11-10 12:57:59 -080013# Make sure user has configured an ssh pubkey
14if [ ! -e /root/.ssh/id_rsa.pub ]; then
15 echo "Public key is missing. This is used to ssh into your instances."
16 echo "Please run ssh-keygen before proceeding"
17 exit 1
18fi
19
Anthony Young43acae42011-11-08 14:23:56 -080020# This directory
21CUR_DIR=$(cd $(dirname "$0") && pwd)
22
Anthony Young723e2d22011-11-11 13:42:09 -080023# Configure trunk jenkins!
24echo "deb http://pkg.jenkins-ci.org/debian binary/" > /etc/apt/sources.list.d/jenkins.list
25wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
26apt-get update
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
38# Setup sudo
39JENKINS_SUDO=/etc/sudoers.d/jenkins
40cat > $JENKINS_SUDO <<EOF
41jenkins ALL = NOPASSWD: ALL
42EOF
43chmod 440 $JENKINS_SUDO
44
45# Setup .gitconfig
46JENKINS_GITCONF=/var/lib/jenkins/hudson.plugins.git.GitSCM.xml
47cat > $JENKINS_GITCONF <<EOF
48<?xml version='1.0' encoding='UTF-8'?>
49<hudson.plugins.git.GitSCM_-DescriptorImpl>
50 <generation>4</generation>
51 <globalConfigName>Jenkins</globalConfigName>
52 <globalConfigEmail>jenkins@rcb.me</globalConfigEmail>
53</hudson.plugins.git.GitSCM_-DescriptorImpl>
54EOF
55
Anthony Youngec67f1e2011-11-09 17:46:28 -080056# Add build numbers
Anthony Young5df68182011-11-10 09:56:12 -080057JOBS=`ls jobs`
58for job in ${JOBS// / }; do
Anthony Youngec67f1e2011-11-09 17:46:28 -080059 if [ ! -e jobs/$job/nextBuildNumber ]; then
60 echo 1 > jobs/$job/nextBuildNumber
61 fi
62done
63
Anthony Young43acae42011-11-08 14:23:56 -080064# Set ownership to jenkins
65chown -R jenkins $CUR_DIR
66
Anthony Young316117a2011-11-09 11:10:26 -080067# Make sure this directory is accessible to jenkins
68if ! su -c "ls $CUR_DIR" jenkins; then
69 echo "Your devstack directory is not accessible by jenkins."
70 echo "There is a decent chance you are trying to run this from a directory in /root."
71 echo "If so, try moving devstack elsewhere (eg. /opt/devstack)."
72 exit 1
73fi
74
Anthony Young48336d02011-11-09 11:12:14 -080075# Move aside old jobs, if present
Anthony Young43acae42011-11-08 14:23:56 -080076if [ ! -h /var/lib/jenkins/jobs ]; then
77 echo "Installing jobs symlink"
78 if [ -d /var/lib/jenkins/jobs ]; then
79 mv /var/lib/jenkins/jobs /var/lib/jenkins/jobs.old
80 fi
Anthony Young43acae42011-11-08 14:23:56 -080081fi
82
Anthony Young48336d02011-11-09 11:12:14 -080083# Set up jobs symlink
84rm -f /var/lib/jenkins/jobs
85ln -s $CUR_DIR/jobs /var/lib/jenkins/jobs
86
Anthony Young43acae42011-11-08 14:23:56 -080087# List of plugins
88PLUGINS=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
89
90# Configure plugins
91for plugin in ${PLUGINS//,/ }; do
92 name=`basename $plugin`
93 dest=/var/lib/jenkins/plugins/$name
94 if [ ! -e $dest ]; then
95 curl -L $plugin -o $dest
96 fi
97done
98
99# Restart jenkins
Anthony Youngc0d4e672011-11-11 13:46:44 -0800100/etc/init.d/jenkins stop || true
101/etc/init.d/jenkins start