forked from samrocketman/jenkins-bootstrap-shared
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jenkins_bootstrap.sh
executable file
·106 lines (92 loc) · 4.08 KB
/
jenkins_bootstrap.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
#Created by Sam Gleske (https://github.com/samrocketman)
#Wed May 20 23:22:07 EDT 2015
#Ubuntu 14.04.2 LTS
#Linux 3.13.0-52-generic x86_64
#GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
#curl 7.35.0 (x86_64-pc-linux-gnu) libcurl/7.35.0 OpenSSL/1.0.1f zlib/1.2.8 libidn/1.28 librtmp/2.3
#Source: https://github.com/samrocketman/jenkins-bootstrap-jervis
#A script which bootstraps a Jenkins installation for executing Jervis Job DSL
#scripts
function cleanup_on() {
#clean up jenkins headers file
[ -n "${JENKINS_HEADERS_FILE}" -a -f "${JENKINS_HEADERS_FILE}" ] && rm -f "${JENKINS_HEADERS_FILE}"
[ -n "${VAGRANT_SSH_CONFIG}" -a -f "${VAGRANT_SSH_CONFIG}" ] && rm -f "${VAGRANT_SSH_CONFIG}"
if [ "$1" = '0' ]; then
echo "Jenkins is ready. Visit ${JENKINS_WEB}/"
echo "User: ${JENKINS_USER}"
[ ! "$JENKINS_USER" = 'admin' ] || echo "Password: ${JENKINS_PASSWORD}"
fi
}
trap 'cleanup_on $?' EXIT
source env.sh
#set password if using vagrant
[ -n "${VAGRANT_JENKINS}" ] && source "${SCRIPT_LIBRARY_PATH}/vagrant-env.sh"
[ -n "${DOCKER_JENKINS}" ] && source "${SCRIPT_LIBRARY_PATH}/docker-env.sh"
export JENKINS_HEADERS_FILE="$(mktemp)"
export JENKINS_USER="${JENKINS_USER:-admin}"
set -e
if [ -e "${SCRIPT_LIBRARY_PATH}/common.sh" ]; then
source "${SCRIPT_LIBRARY_PATH}/common.sh"
else
echo "ERROR could not find ${SCRIPT_LIBRARY_PATH}/common.sh"
echo "Perhaps environment variable SCRIPT_LIBRARY_PATH is not set correctly."
exit 1
fi
#provision jenkins and plugins
if [ -z "${REMOTE_JENKINS}" -a -z "${VAGRANT_JENKINS}" -a -z "${DOCKER_JENKINS}" ]; then
echo 'Downloading specific versions of Jenkins and plugins...'
./gradlew getjenkins getplugins
fi
if [ -d "./plugins" ]; then
mkdir -p "${JENKINS_HOME}/plugins"
( cd "./plugins/"; ls -1d * ) | while read x; do
if [ ! -e "${JENKINS_HOME}/plugins/${x}" ]; then
echo "Copying ${x} to JENKINS_HOME"
cp -r "./plugins/${x}" "${JENKINS_HOME}/plugins/"
#pin plugin versions
#https://wiki.jenkins-ci.org/display/JENKINS/Pinned+Plugins
touch "${JENKINS_HOME}/plugins/${x}.pinned"
fi
done
fi
#download jenkins, start it up, and update the plugins
if [ -z "${REMOTE_JENKINS}" -a -z "${VAGRANT_JENKINS}" -a -z "${DOCKER_JENKINS}" ]; then
mkdir -p "${JENKINS_HOME}/init.groovy.d"
if [ -d "./scripts/init.groovy.d" ]; then
( cd ./scripts/init.groovy.d/; ls -1d * ) | while read x; do
if [ ! -e "${JENKINS_HOME}/init.groovy.d/${x}" ]; then
echo "Copying init.groovy.d/${x} to JENKINS_HOME"
command cp ./scripts/init.groovy.d/"${x}" "${JENKINS_HOME}/init.groovy.d/"
fi
done
fi
if [ -d "${SCRIPT_LIBRARY_PATH}/init.groovy.d" ]; then
( cd "${SCRIPT_LIBRARY_PATH}"/init.groovy.d/; ls -1d * ) | while read x; do
if [ ! -e "${JENKINS_HOME}/init.groovy.d/${x}" ]; then
echo "Copying init.groovy.d/${x} to JENKINS_HOME"
command cp "${SCRIPT_LIBRARY_PATH}"/init.groovy.d/"${x}" "${JENKINS_HOME}/init.groovy.d/"
fi
done
fi
if [ ! -e "${JENKINS_WAR}" ]; then
"${SCRIPT_LIBRARY_PATH}/provision_jenkins.sh" download-file "${jenkins_url}" "${JENKINS_WAR}"
fi
#check for running jenkins or try to start it
if ! "${SCRIPT_LIBRARY_PATH}/provision_jenkins.sh" status; then
"${SCRIPT_LIBRARY_PATH}/provision_jenkins.sh" start
fi
fi
#wait for jenkins to become available
"${SCRIPT_LIBRARY_PATH}/provision_jenkins.sh" url-ready "${JENKINS_WEB}/jnlpJars/jenkins-cli.jar"
#persist credentials
export JENKINS_PASSWORD="${JENKINS_PASSWORD:-$(<"${JENKINS_HOME}"/secrets/initialAdminPassword)}"
"${SCRIPT_LIBRARY_PATH}"/jenkins-call-url -a -m HEAD -o /dev/null ${JENKINS_WEB}
if grep -- '^ \+getplugins' dependencies.gradle > /dev/null; then
jenkins_console --script "${SCRIPT_LIBRARY_PATH}/console-skip-2.0-wizard.groovy"
fi
jenkins_console --script "${SCRIPT_LIBRARY_PATH}/configure-disable-usage-stats.groovy"
#configure jenkins agent credentials
#jenkins_console --script "${SCRIPT_LIBRARY_PATH}/credentials-jenkins-agent.groovy"
#disable agent -> master security
#jenkins_console --script "${SCRIPT_LIBRARY_PATH}/security-disable-agent-master.groovy"