jenkins.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #! /bin/bash -e
  2. : "${JENKINS_WAR:="/usr/share/jenkins/jenkins.war"}"
  3. : "${JENKINS_HOME:="/var/jenkins_home"}"
  4. : "${COPY_REFERENCE_FILE_LOG:="${JENKINS_HOME}/copy_reference_file.log"}"
  5. : "${REF:="/usr/share/jenkins/ref"}"
  6. touch "${COPY_REFERENCE_FILE_LOG}" || { echo "Can not write to ${COPY_REFERENCE_FILE_LOG}. Wrong volume permissions?"; exit 1; }
  7. echo "--- Copying files at $(date)" >> "$COPY_REFERENCE_FILE_LOG"
  8. find "${REF}" \( -type f -o -type l \) -exec bash -c '. /usr/local/bin/jenkins-support; for arg; do copy_reference_file "$arg"; done' _ {} +
  9. sudo groupadd -o -g ${HOST_DOCKER_GROUP} jenkins_docker | true
  10. sudo usermod -aG jenkins_docker jenkins
  11. newgrp jenkins_docker
  12. docker ps
  13. # if `docker run` first argument start with `--` the user is passing jenkins launcher arguments
  14. if [[ $# -lt 1 ]] || [[ "$1" == "--"* ]]; then
  15. # shellcheck disable=SC2001
  16. effective_java_opts=$(sed -e 's/^ $//' <<<"$JAVA_OPTS $JENKINS_JAVA_OPTS")
  17. # read JAVA_OPTS and JENKINS_OPTS into arrays to avoid need for eval (and associated vulnerabilities)
  18. java_opts_array=()
  19. while IFS= read -r -d '' item; do
  20. java_opts_array+=( "$item" )
  21. done < <([[ $effective_java_opts ]] && xargs printf '%s\0' <<<"$effective_java_opts")
  22. readonly agent_port_property='jenkins.model.Jenkins.slaveAgentPort'
  23. if [ -n "${JENKINS_SLAVE_AGENT_PORT:-}" ] && [[ "${effective_java_opts:-}" != *"${agent_port_property}"* ]]; then
  24. java_opts_array+=( "-D${agent_port_property}=${JENKINS_SLAVE_AGENT_PORT}" )
  25. fi
  26. readonly lifecycle_property='hudson.lifecycle'
  27. if [[ "${JAVA_OPTS:-}" != *"${lifecycle_property}"* ]]; then
  28. java_opts_array+=( "-D${lifecycle_property}=hudson.lifecycle.ExitLifecycle" )
  29. fi
  30. if [[ "$DEBUG" ]] ; then
  31. java_opts_array+=( \
  32. '-Xdebug' \
  33. '-Xrunjdwp:server=y,transport=dt_socket,address=*:5005,suspend=y' \
  34. )
  35. fi
  36. jenkins_opts_array=( )
  37. while IFS= read -r -d '' item; do
  38. jenkins_opts_array+=( "$item" )
  39. done < <([[ $JENKINS_OPTS ]] && xargs printf '%s\0' <<<"$JENKINS_OPTS")
  40. exec java -Duser.home="$JENKINS_HOME" "${java_opts_array[@]}" -jar "${JENKINS_WAR}" "${jenkins_opts_array[@]}" "$@"
  41. fi
  42. # As argument is not jenkins, assume user wants to run a different process, for example a `bash` shell to explore this image
  43. exec "$@"