blob: bd17f1c8d95e575107df4e35901358cf047aef26 [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
16# Install software
Anthony Youngc18af142011-11-09 12:20:37 -080017DEPS="jenkins cloud-utils"
Anthony Young43acae42011-11-08 14:23:56 -080018apt-get install -y --force-yes $DEPS
19
20# Install jenkins
21if [ ! -e /var/lib/jenkins ]; then
22 echo "Jenkins installation failed"
23 exit 1
24fi
25
26# Setup sudo
27JENKINS_SUDO=/etc/sudoers.d/jenkins
28cat > $JENKINS_SUDO <<EOF
29jenkins ALL = NOPASSWD: ALL
30EOF
31chmod 440 $JENKINS_SUDO
32
33# Setup .gitconfig
34JENKINS_GITCONF=/var/lib/jenkins/hudson.plugins.git.GitSCM.xml
35cat > $JENKINS_GITCONF <<EOF
36<?xml version='1.0' encoding='UTF-8'?>
37<hudson.plugins.git.GitSCM_-DescriptorImpl>
38 <generation>4</generation>
39 <globalConfigName>Jenkins</globalConfigName>
40 <globalConfigEmail>jenkins@rcb.me</globalConfigEmail>
41</hudson.plugins.git.GitSCM_-DescriptorImpl>
42EOF
43
44# Set ownership to jenkins
45chown -R jenkins $CUR_DIR
46
Anthony Young316117a2011-11-09 11:10:26 -080047# Make sure this directory is accessible to jenkins
48if ! su -c "ls $CUR_DIR" jenkins; then
49 echo "Your devstack directory is not accessible by jenkins."
50 echo "There is a decent chance you are trying to run this from a directory in /root."
51 echo "If so, try moving devstack elsewhere (eg. /opt/devstack)."
52 exit 1
53fi
54
Anthony Young48336d02011-11-09 11:12:14 -080055# Move aside old jobs, if present
Anthony Young43acae42011-11-08 14:23:56 -080056if [ ! -h /var/lib/jenkins/jobs ]; then
57 echo "Installing jobs symlink"
58 if [ -d /var/lib/jenkins/jobs ]; then
59 mv /var/lib/jenkins/jobs /var/lib/jenkins/jobs.old
60 fi
Anthony Young43acae42011-11-08 14:23:56 -080061fi
62
Anthony Young48336d02011-11-09 11:12:14 -080063# Set up jobs symlink
64rm -f /var/lib/jenkins/jobs
65ln -s $CUR_DIR/jobs /var/lib/jenkins/jobs
66
Anthony Young43acae42011-11-08 14:23:56 -080067# List of plugins
68PLUGINS=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
69
70# Configure plugins
71for plugin in ${PLUGINS//,/ }; do
72 name=`basename $plugin`
73 dest=/var/lib/jenkins/plugins/$name
74 if [ ! -e $dest ]; then
75 curl -L $plugin -o $dest
76 fi
77done
78
79# Restart jenkins
80restart jenkins