blob: 567a05629c060aab1d29b00aaaec6508dab404c4 [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
Anthony Youngec67f1e2011-11-09 17:46:28 -080044# Add build numbers
Anthony Young5df68182011-11-10 09:56:12 -080045JOBS=`ls jobs`
46for job in ${JOBS// / }; do
Anthony Youngec67f1e2011-11-09 17:46:28 -080047 if [ ! -e jobs/$job/nextBuildNumber ]; then
48 echo 1 > jobs/$job/nextBuildNumber
49 fi
50done
51
Anthony Young43acae42011-11-08 14:23:56 -080052# Set ownership to jenkins
53chown -R jenkins $CUR_DIR
54
Anthony Young316117a2011-11-09 11:10:26 -080055# Make sure this directory is accessible to jenkins
56if ! su -c "ls $CUR_DIR" jenkins; then
57 echo "Your devstack directory is not accessible by jenkins."
58 echo "There is a decent chance you are trying to run this from a directory in /root."
59 echo "If so, try moving devstack elsewhere (eg. /opt/devstack)."
60 exit 1
61fi
62
Anthony Young48336d02011-11-09 11:12:14 -080063# Move aside old jobs, if present
Anthony Young43acae42011-11-08 14:23:56 -080064if [ ! -h /var/lib/jenkins/jobs ]; then
65 echo "Installing jobs symlink"
66 if [ -d /var/lib/jenkins/jobs ]; then
67 mv /var/lib/jenkins/jobs /var/lib/jenkins/jobs.old
68 fi
Anthony Young43acae42011-11-08 14:23:56 -080069fi
70
Anthony Young48336d02011-11-09 11:12:14 -080071# Set up jobs symlink
72rm -f /var/lib/jenkins/jobs
73ln -s $CUR_DIR/jobs /var/lib/jenkins/jobs
74
Anthony Young43acae42011-11-08 14:23:56 -080075# List of plugins
76PLUGINS=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
77
78# Configure plugins
79for plugin in ${PLUGINS//,/ }; do
80 name=`basename $plugin`
81 dest=/var/lib/jenkins/plugins/$name
82 if [ ! -e $dest ]; then
83 curl -L $plugin -o $dest
84 fi
85done
86
87# Restart jenkins
Anthony Youngec38c402011-11-10 09:42:28 -080088stop jenkins || true
89start jenkins