forked from odavid/my-bloody-jenkins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjenkins.sh
executable file
·76 lines (67 loc) · 3.18 KB
/
jenkins.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
#! /bin/bash -e
if [[ $# -lt 1 ]] || [[ "$1" == "-"* ]]; then
JAVA_OPTS_VARIABLES=$(compgen -v | while read line; do echo $line | grep JAVA_OPTS_;done) || true
for key in $JAVA_OPTS_VARIABLES; do
echo "adding: ${key} to JAVA_OPTS"
export JAVA_OPTS="$JAVA_OPTS ${!key}"
done
if [ -n "${JENKINS_ENV_CONFIG_YAML}" ]; then
echo -n "$JENKINS_ENV_CONFIG_YAML" > $CONFIG_FILE_LOCATION
unset JENKINS_ENV_CONFIG_YAML
elif [ -n "${JENKINS_ENV_CONFIG_YML_URL}" ]; then
echo "Fetching config from URL: ${JENKINS_ENV_CONFIG_YML_URL}"
watch-file.sh \
--cache-dir $CONFIG_CACHE_DIR \
--url "${JENKINS_ENV_CONFIG_YML_URL}" \
--filename $CONFIG_FILE_LOCATION \
--skip-watch
if [ "$JENKINS_ENV_CONFIG_YML_URL_DISABLE_WATCH" != 'true' ]; then
echo "Watching config from URL: ${JENKINS_ENV_CONFIG_YML_URL} in the backgroud"
nohup watch-file.sh \
--cache-dir $CONFIG_CACHE_DIR \
--url "${JENKINS_ENV_CONFIG_YML_URL}" \
--filename $CONFIG_FILE_LOCATION \
--polling-interval "${JENKINS_ENV_CONFIG_YML_URL_POLLING:-30}" \
--command 'update-config.sh' &
fi
unset AWS_ACCESS_KEY_ID
unset AWS_SECRET_ACCESS_KEY
fi
if [ -n "$JENKINS_ENV_PLUGINS" ]; then
echo "Installing additional plugins $JENKINS_ENV_PLUGINS"
install-plugins.sh $(echo $JENKINS_ENV_PLUGINS | tr ',' ' ')
chown jenkins:jenkins /usr/share/jenkins/ref/
echo "Installing additional plugins. Done..."
fi
# Because we are in docker, we need to fetch the real IP of jenkins, so ecs/kubernetes/docker cloud slaves will
# be able to connect to it
# If it is running with docker network=host, then the default ip address will be sufficient
if [ -n "${JENKINS_ENV_HOST_IP}" ]; then
export JENKINS_IP_FOR_SLAVES="${JENKINS_ENV_HOST_IP}"
unset JENKINS_ENV_HOST_IP
elif [ -n "${JENKINS_ENV_HOST_IP_CMD}" ]; then
export JENKINS_IP_FOR_SLAVES="$(eval ${JENKINS_ENV_HOST_IP_CMD})" || true
unset JENKINS_ENV_HOST_IP_CMD
fi
echo "JENKINS_IP_FOR_SLAVES = ${JENKINS_IP_FOR_SLAVES}"
# This is important if you let docker create the host mounted volumes.
# We need to make sure they will be owned by the jenkins user
mkdir -p /jenkins-workspace-home/workspace
if [ "jenkins" != "$(stat -c %U /jenkins-workspace-home/workspace)" ]; then
chown -R jenkins:jenkins /jenkins-workspace-home
fi
if [ "jenkins" != "$(stat -c %U ${JENKINS_HOME})" ]; then
chown -R jenkins:jenkins $JENKINS_HOME
fi
# To enable docker cloud based on docker socket,
# we need to add jenkins user to the docker group
if [ -S /var/run/docker.sock ]; then
DOCKER_SOCKET_OWNER_GROUP_ID=$(stat -c %g /var/run/docker.sock)
groupadd -for -g ${DOCKER_SOCKET_OWNER_GROUP_ID} docker
id jenkins -G -n | grep docker || usermod -aG docker jenkins
fi
# This changes the actual command to run the original jenkins entrypoint
# using the jenkins user
set -- gosu jenkins /usr/local/bin/jenkins-orig.sh "$@"
fi
exec "$@"