Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ac-hibbert
Copy link

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

Change-Id: I79bb00935a8d4a28a5e5f8b24fc70aafbef38695
Copy link
Member

@timja timja left a 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 ?

@MarkEWaite
Copy link
Contributor

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 .override technique allows a single file to always replace the same file in the JENKINS_HOME directory. Should we extend the concept to an entire directory?

Copy link

@whoami-anoint whoami-anoint left a 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.

@saper
Copy link
Collaborator

saper commented Oct 8, 2024

Would that be enough if a directory pointed to by a (not yet existing) environment variable INIT_GROOVY_D is supplied on the build host and copied over inside of the image?

(Anyway it might be easier to use -v at runtime to mount something else as init.groovy.d)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants