-
Notifications
You must be signed in to change notification settings - Fork 2
/
jenkins.sh
executable file
·77 lines (67 loc) · 2.4 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
77
#! /bin/bash -e
# Copy files from /usr/share/jenkins/ref into /var/jenkins_home
# So the initial JENKINS-HOME is set with expected content.
# Don't override, as this is just a reference setup, and use from UI
# can then change this, upgrade plugins, etc.
copy_reference_file() {
f=${1%/}
rel=${f:23}
dir=$(dirname ${f})
if [[ ${rel} = README.md ]]
then
return
fi
echo "Ref: $rel copied."
mkdir -p /var/jenkins_home/${dir:23}
cp -r /usr/share/jenkins/ref/${rel} /var/jenkins_home/${rel};
}
echo "User context is : $(id)"
# if `docker run` first argument start with `--` the user is passing jenkins launcher arguments
if [[ $# -lt 1 ]] || [[ "$1" == "--"* ]]; then
export -f copy_reference_file
echo "Cleaning plugins, and init.groovy.d"
rm -f /var/jenkins_home/plugins/*.hpi /var/jenkins_home/plugins/*.jpi /var/jenkins_home/init.groovy.d/*.groovy
find /usr/share/jenkins/ref/ -type f -exec bash -c "copy_reference_file '{}'" \;
if [[ -f /usr/share/jenkins/ref/jplugins.lock ]]
then
cp -v /usr/share/jenkins/ref/jplugins.lock /var/jenkins_home/
fi
for FILE in /var/jenkins_home/jenkins.start.d/*
do
[[ "$FILE" =~ \.sh$ ]] || continue
if [[ "$FILE" =~ source\.sh$ ]]
then
echo "Sourcing '$FILE'"
source "$FILE"
else
echo "Executing '$FILE'..."
bash $FILE
fi
done
if [ "$JENKINS_CREDENTIALS" = "" ]
then
JENKINS_CREDENTIALS="/tmp/jenkins_credentials.sh"
fi
if [ -e "$JENKINS_CREDENTIALS" ]
then
echo "Loading $JENKINS_CREDENTIALS..."
source "$JENKINS_CREDENTIALS"
else
echo "$JENKINS_CREDENTIALS NOT FOUND. No credentials loaded."
fi
if [ "$GIT_EMAIL" = "" ] || [ "$GIT_USERNAME" = "" ]
then
echo "Warning! No GIT_EMAIL or GIT_USERNAME properly configured (missing in /tmp/jenkins_credentials.sh?)"
fi
echo "
Values set are:
SEED_JOBS_REPO : '$SEED_JOBS_REPO'
GIT_USER : '$GIT_USER'
GIT_PASSWORD : '${GIT_PASSWORD:+'***'}'
GIT_EMAIL : '${GIT_EMAIL:='jenkins@demo.net'}'
GIT_USERNAME : '${GIT_USERNAME:='Jenkins builder'}'"
git config --global user.email "$GIT_EMAIL" && git config --global user.name "$GIT_USERNAME"
exec java $JAVA_OPTS -jar /usr/*/jenkins/jenkins.war $JENKINS_OPTS "$@"
fi
# As argument is not jenkins, assume user want to run his own process, for sample a `bash` shell to explore this image
exec "$@"