@@ -21,6 +21,8 @@ JENKINS_KEYSTORE="${JENKINS_KEYSTORE:-~~HTTPS_KEYSTORE~~}"
21
21
JENKINS_DEBUG_LEVEL=" ${JENKINS_DEBUG_LEVEL:- 5} "
22
22
JENKINS_HANDLER_MAX=" ${JENKINS_HANDLER_MAX:- ~~HTTP_MAX_WORKER_THREADS~~} "
23
23
JENKINS_HANDLER_IDLE=" ${JENKINS_HANDLER_IDLE:- ~~HTTP_MAX_IDLE_THREADS~~} "
24
+ JENKINS_GIT_USER=" ${JENKINS_GIT_USER:- Jenkins Automation} "
25
+ JENKINS_GIT_EMAIL=" ${JENKINS_GIT_EMAIL:- noreply@ example.com} "
24
26
[ -n " ${JENKINS_ARGS} " ] || JENKINS_ARGS=" -~~ADDITIONAL_JENKINS_ARGS~~"
25
27
26
28
if [ " ${JENKINS_KEYSTORE} " ]; then
@@ -62,6 +64,48 @@ if [ -d "@@PREFIX@@/lib/@@ARTIFACTNAME@@/scripts/init.groovy.d/" ]; then
62
64
mkdir -p " ${JENKINS_HOME} /init.groovy.d"
63
65
rsync -a --delete-after " @@PREFIX@@/lib/@@ARTIFACTNAME@@/scripts/init.groovy.d/" " ${JENKINS_HOME} /init.groovy.d/"
64
66
fi
67
+ # configure tracking JENKINS_HOME with git
68
+ if [ ! -e " ${JENKINS_HOME} /.gitignore" ]; then
69
+ echo " Creating '${JENKINS_HOME} /.gitignore'."
70
+ cp " @@PREFIX@@/lib/@@ARTIFACTNAME@@/share/gitignore" " ${JENKINS_HOME} /.gitignore"
71
+ chmod 644 " ${JENKINS_HOME} /.gitignore"
72
+ fi
73
+ if ! diff -q " @@PREFIX@@/lib/@@ARTIFACTNAME@@/share/gitignore" " ${JENKINS_HOME} /.gitignore" ; then
74
+ diff -u " @@PREFIX@@/lib/@@ARTIFACTNAME@@/share/gitignore" " ${JENKINS_HOME} /.gitignore"
75
+ echo " To resolve the changes you can optionally:"
76
+ echo " cp -f '@@PREFIX@@/lib/@@ARTIFACTNAME@@/share/gitignore' '${JENKINS_HOME} /.gitignore'"
77
+ fi
78
+ # create git repo if it doesn't exist
79
+ if [ ! -d " ${JENKINS_HOME} /.git" ]; then
80
+ (
81
+ cd " ${JENKINS_HOME} "
82
+ git init
83
+ git config user.name " ${JENKINS_GIT_USER} "
84
+ git config user.email " ${JENKINS_GIT_EMAIL} "
85
+ git add .gitignore
86
+ git commit -m ' initial commit'
87
+ )
88
+ fi
89
+
90
+ # commit unsaved configuration before starting up/upgrading
91
+ git config --local --get user.name || git config user.name " ${JENKINS_GIT_USER} "
92
+ git config --local --get user.email || git config user.email " ${JENKINS_GIT_EMAIL} "
93
+ git add -A
94
+ git commit -m ' pre-start checkpoint commit saving configs'
95
+
96
+ # save the current version of the bootstrapper to JENKINS_HOME on startup
97
+ echo " Overwriting manifest in '${JENKINS_HOME} /plugins/@@MANIFEST@@'."
98
+ cp -f " @@PREFIX@@/lib/@@ARTIFACTNAME@@/@@MANIFEST@@" " ${JENKINS_HOME} /"
99
+ echo ' @@COMMIT@@' > " ${JENKINS_HOME} /@@PACKAGENAME@@-commit"
100
+
101
+ # overwrite dailycommit which is meant for daily
102
+ echo " Overwriting '${JENKINS_HOME} /dailycommit.sh'."
103
+ cp -f " @@PREFIX@@/lib/@@ARTIFACTNAME@@/share/dailycommit.sh" " ${JENKINS_HOME} /"
104
+ chmod 755 " ${JENKINS_HOME} /dailycommit.sh"
105
+
106
+ for x in ~ /.bash_profile ~ /.bashrc; do
107
+ grep JENKINS_HOME " ${x} " || echo " export JENKINS_HOME=\" ${JENKINS_HOME} \" " >> " ${x} "
108
+ done
65
109
66
110
echo " Starting @@PRODUCTNAME@@"
67
111
# launch in foreground for docker to collect logs on stdout
0 commit comments