blob: e71e9e0e409a4cdc9a5656f82930bfcd9fc2ee3f [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
17DEPS="jenkins"
18apt-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 Young43acae42011-11-08 14:23:56 -080055# Set up jobs symlink
56if [ ! -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
61 ln -s $CUR_DIR/jobs /var/lib/jenkins/jobs
62fi
63
64# List of plugins
65PLUGINS=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
66
67# Configure plugins
68for plugin in ${PLUGINS//,/ }; do
69 name=`basename $plugin`
70 dest=/var/lib/jenkins/plugins/$name
71 if [ ! -e $dest ]; then
72 curl -L $plugin -o $dest
73 fi
74done
75
76# Restart jenkins
77restart jenkins