-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PRE_CLEAR_INIT_GROOVY_D: Add in ability to pre-clear the init.groovy.d folder #900
base: master
Are you sure you want to change the base?
Conversation
Change-Id: I79bb00935a8d4a28a5e5f8b24fc70aafbef38695
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine, anyone else got any thoughts on it? @MarkEWaite ?
It seems like this Is introducing a specific implementation of a more general concept. I think the general concept is that a subdirectory in JENKINS_HOME is to be completely managed by the contents copied from the base image. The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Default values for JENKINS_WAR and JENKINS_HOME
JENKINS_WAR="${JENKINS_WAR:-/usr/share/jenkins/jenkins.war}"
JENKINS_HOME="${JENKINS_HOME:-/var/jenkins_home}"
# If PRE_CLEAR_INIT_GROOVY_D variable is not empty, remove init.groovy.d directory
if [[ -n "$PRE_CLEAR_INIT_GROOVY_D" ]]; then
rm -rf "${JENKINS_HOME}/init.groovy.d"
fi
# Default values for COPY_REFERENCE_FILE_LOG and REF
COPY_REFERENCE_FILE_LOG="${COPY_REFERENCE_FILE_LOG:-${JENKINS_HOME}/copy_reference_file.log}"
REF="${REF:-/usr/share/jenkins/ref}"
# Attempt to create the COPY_REFERENCE_FILE_LOG file and handle errors if any
touch "$COPY_REFERENCE_FILE_LOG" || {
echo "Cannot write to ${COPY_REFERENCE_FILE_LOG}. Wrong volume permissions?" >&2
exit 1
}
Note:
-
Add Comments: Although the code is relatively straightforward, adding comments can make it more understandable, especially for others who might read or maintain the code in the future.
-
Consistent Quoting: The code already uses double quotes around variables in most places, which is good for handling spaces and special characters in values. Ensure consistency in using double quotes throughout the script.
-
Improve Error Handling: The code includes some basic error handling for the touch command failure. Depending on the context, you might want to include more robust error handling to handle various failure scenarios gracefully.
Would that be enough if a directory pointed to by a (not yet existing) environment variable (Anyway it might be easier to use |
Currently you can populate the init.groovy.d folder with scripts that you want to run and append .override if you require to override current scripts of the same name. However you cannot override the whole directory, this may be necessary if you wish to remove scripts, change names of scripts, change run order etc. This fix allows the user to pre-clear the init.groovy.d folder prior to the files being copied into place, meaning the files you copy over to $REF/init.groovy.d will be the only ones present