Last active
April 11, 2019 07:33
-
-
Save keirbadger/e1a6e08c370aa1618c493ba644f611dc to your computer and use it in GitHub Desktop.
jenkins docker container entrypoint script with debug enabled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash -e | |
: "${JENKINS_WAR:="/usr/share/jenkins/jenkins.war"}" | |
: "${JENKINS_HOME:="/var/jenkins_home"}" | |
touch "${COPY_REFERENCE_FILE_LOG}" || { echo "Can not write to ${COPY_REFERENCE_FILE_LOG}. Wrong volume permissions?"; exit 1; } | |
echo "--- Copying files at $(date)" >> "$COPY_REFERENCE_FILE_LOG" | |
find /usr/share/jenkins/ref/ \( -type f -o -type l \) -exec bash -c '. /usr/local/bin/jenkins-support; for arg; do copy_reference_file "$arg"; done' _ {} + | |
# if `docker run` first argument start with `--` the user is passing jenkins launcher arguments | |
if [[ $# -lt 1 ]] || [[ "$1" == "--"* ]]; then | |
# read JAVA_OPTS and JENKINS_OPTS into arrays to avoid need for eval (and associated vulnerabilities) | |
java_opts_array=() | |
while IFS= read -r -d '' item; do | |
java_opts_array+=( "$item" ) | |
done < <([[ $JAVA_OPTS ]] && xargs printf '%s\0' <<<"$JAVA_OPTS") | |
if [[ "$DEBUG" ]] ; then | |
java_opts_array+=( \ | |
'-Xdebug' \ | |
'-Xrunjdwp:server=y,transport=dt_socket,address=5005,suspend=n' \ | |
) | |
fi | |
jenkins_opts_array=( ) | |
while IFS= read -r -d '' item; do | |
jenkins_opts_array+=( "$item" ) | |
done < <([[ $JENKINS_OPTS ]] && xargs printf '%s\0' <<<"$JENKINS_OPTS") | |
exec java -Duser.home="$JENKINS_HOME" "${java_opts_array[@]}" -jar ${JENKINS_WAR} "${jenkins_opts_array[@]}" "$@" | |
fi | |
# As argument is not jenkins, assume user want to run his own process, for example a `bash` shell to explore this image | |
exec "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment