@@ -91,16 +91,16 @@ launch=${launch:-docker}
9191j_url=https://repo.jenkins-ci.org/public/org/jenkins-ci/main/jenkins-war/${j_vrsn} /jenkins-war-${j_vrsn} .war
9292
9393# Make or Clean WORKSPACE
94- if [[ -d ${workspace} ]]; then
95- rm -rf ${workspace} /Dockerfile \
96- ${workspace} /docker-jenkins \
97- ${workspace} /plugins.* \
98- ${workspace} /install-plugins.sh \
99- ${workspace} /jenkins.sh \
100- ${workspace} /jenkins-support \
101- ${workspace} /init.groovy
94+ if [[ -d " ${workspace} " ]]; then
95+ rm -rf " ${workspace} /Dockerfile" \
96+ " ${workspace} /docker-jenkins" \
97+ " ${workspace} /plugins.*" \
98+ " ${workspace} /install-plugins.sh" \
99+ " ${workspace} /jenkins.sh" \
100+ " ${workspace} /jenkins-support" \
101+ " ${workspace} /init.groovy"
102102else
103- mkdir -p ${workspace}
103+ mkdir -p " ${workspace} "
104104fi
105105
106106# Determine the prefix of the Dockerfile's base image
@@ -119,7 +119,7 @@ case ${ARCH} in
119119esac
120120
121121# Move Into the WORKSPACE
122- cd ${workspace}
122+ cd " ${workspace} "
123123
124124# Make the Dockerfile
125125# ###############################################################################
@@ -200,31 +200,33 @@ EOF
200200# ###############################################################################
201201
202202# Build the image
203- docker build -t ${img_name} .
203+ docker build -t " ${img_name} " .
204204
205- if [[ ${launch} == " docker" ]]; then
205+ if [[ " ${launch} " == " docker" ]]; then
206206
207207 # Ensure directories that will be mounted exist
208- if [[ ! -z ${host_import_mnt} && ! -d ${host_import_mnt} ]]; then
209- mkdir -p ${host_import_mnt}
208+ if [[ -n " ${host_import_mnt} " && ! -d " ${host_import_mnt} " ]]; then
209+ mkdir -p " ${host_import_mnt} "
210210 fi
211211
212- if [[ ! -d ${home_mnt} ]]; then
213- mkdir -p ${home_mnt}
212+ if [[ ! -d " ${home_mnt} " ]]; then
213+ mkdir -p " ${home_mnt} "
214214 fi
215215
216216 # Ensure directories that will be mounted are owned by the jenkins user
217217 if [[ " $( id -u) " != 0 ]]; then
218218 echo " Not running as root:"
219219 echo " Checking if j_gid and j_uid are the owners of mounted directories"
220- test_1=$( ls -nd ${home_mnt} | awk ' {print $3 " " $4}' )
220+ # shellcheck disable=SC2012 # use ls to get permissions.
221+ test_1=" $( ls -nd " ${home_mnt} " | awk ' {print $3 " " $4}' ) "
221222 if [[ " ${test_1} " != " ${j_uid} ${j_gid} " ]]; then
222223 echo " Owner of ${home_mnt} is not the jenkins user"
223224 echo " ${test_1} != ${j_uid} ${j_gid} "
224225 will_fail=1
225226 fi
226- if [[ ! -z " ${host_import_mnt} " ]]; then
227- test_2=$( ls -nd ${host_import_mnt} | awk ' {print $3 " " $4}' )
227+ if [[ -n " ${host_import_mnt} " ]]; then
228+ # shellcheck disable=SC2012 # use ls to get permissions.
229+ test_2=" $( ls -nd " ${host_import_mnt} " | awk ' {print $3 " " $4}' ) "
228230 if [[ " ${test_2} " != " ${j_uid} ${j_gid} " ]]; then
229231 echo " Owner of ${host_import_mnt} is not the jenkins user"
230232 echo " ${test_2} != ${j_uid} ${j_gid} "
@@ -237,27 +239,29 @@ if [[ ${launch} == "docker" ]]; then
237239 exit 1
238240 fi
239241 else
240- if [[ ! -z ${host_import_mnt} ]]; then
241- chown -R ${j_uid} :${j_gid} ${host_import_mnt}
242+ if [[ -n " ${host_import_mnt} " ]]; then
243+ chown -R " ${j_uid} :${j_gid} " " ${host_import_mnt} "
242244 fi
243- chown -R ${j_uid} :${j_gid} ${home_mnt}
245+ chown -R " ${j_uid} :${j_gid} " " ${home_mnt} "
244246 fi
245247
246248 # If we don't have import mount don't add to docker command
247- if [[ ! -z ${host_import_mnt} ]]; then
249+ if [[ -n " ${host_import_mnt} " ]]; then
248250 import_vol_cmd=" -v ${host_import_mnt} :${cont_import_mnt} "
249251 fi
250252 # Launch the jenkins image with Docker
253+ # shellcheck disable=SC2086 # import_vol_cmd is intentially word-split.
251254 docker run -d \
252255 ${import_vol_cmd} \
253- -v ${home_mnt} :${j_home} \
254- -p ${http_port} :8080 \
255- -p ${agent_port} :${agent_port} \
256- --env JAVA_OPTS=\" ${java_options} \" \
257- --env JENKINS_OPTS=\" ${jenkins_options} \" \
258- ${img_name}
256+ -v " ${home_mnt} :${j_home} " \
257+ -p " ${http_port} :8080" \
258+ -p " ${agent_port} :${agent_port} " \
259+ --env JAVA_OPTS=\" " ${java_options} " \" \
260+ --env JENKINS_OPTS=\" " ${jenkins_options} " \" \
261+ " ${img_name} "
259262
260263elif [[ ${launch} == " k8s" ]]; then
261264 # launch using the k8s template
262- source ${build_scripts_dir} /kubernetes/kubernetes-launch.sh Build-Jenkins false false
265+ # shellcheck source=kubernetes/kubernetes-launch.sh
266+ source " ${build_scripts_dir} /kubernetes/kubernetes-launch.sh" Build-Jenkins false false
263267fi
0 commit comments