Jenkins updating init.groovy.d files in a docker container - docker

I have a series of Groovy scripts in groovy.init.d inside a Docker container which has the JENKINS_HOME mounted to the host file system.
I'm using the standard jenkins-support file to copy the plugins et al.
https://raw.githubusercontent.com/jenkinsci/docker/master/jenkins-support
When I add new files to groovy.init.d, the script adds them no problem, but if I update the scripts then the newer ones are not overwriting the existing ones. I want the groovy files added to the Docker image to overwrite what is on the file system.
Is this possible?

Yes, put .override extension to your file and put to /usr/share/jenkins/ref/init.groovy.d/ on the
image example
/usr/share/jenkins/ref/init.groovy.d/security.groovy.override .
When jenkins starts it will replace existing
/var/jenkins_home/init.groovy.d/security.groovy
file's content with the one above.

Related

What is the use of multiple Jenkins plugin directory?

I was trying to create a Jenkins master slave system using Helm Charts. [ https://github.com/jenkinsci/helm-charts/blob/main/charts/jenkins/README.md ].
After deploying I can see the plugins are stored in two locations in the pod/ docker container.
1. /var/jenkins_home/plugins
2. /usr/share/jenkins/ref/plugins
What's the relation between these two? JENKINS_HOME is configured as /var/jenkins_home/. If I need to backup the plugins which directory should I backup ?
For a plugin named ace-editor, I can see these many files in respective folders.
/usr/share/jenkins/ref/plugins contains (1 file) -> ace-editor.jpi
/var/jenkins_home/plugins contains (4 file) -> ace-editor.jpi, ace-editor.jpi, ace-editor.jpi.pinned, ace-editor.jpi.version_from_image
What does this mean?
The directory to back up is always /var/jenkins_home. It is meant to be a persistent volume with all the data. /var/jenkins_home/plugins contains the downloaded .jpi plugin files and directories where each plugin has been unpacked.
The directory /usr/share/jenkins/ref is a "reference" directory on the container image. This means /usr/share/jenkins/ref/plugins is used as a starting point to install a base set of plugins into /var/jenkins_home/plugins the first time you run Jenkins.
The log file containing info about installed reference files is /var/jenkins_home/copy_reference_file.log.
The files with suffix .pinned or .version_from_image are used to control subsequent behaviour for example when plugins have been updated in jenkins_home from the UI and/or to the reference directory in a newer container image. Some users might want to use the bundled plugins in the image only for initial startup, others as the definitive source of all updates. See also environmental variables described in the documentation.
If you want to examine the inner workings you can find shell script jenkins.sh and functions source jenkins-support in the repository root or in /usr/local/bin on the image.

Jenkins - How can I change the plugin directory?

Cheers everyone,
I am in a Kubernetes environment and Jenkins plugins are installed at image build time via means of Jenkins CLI.
This causes the Image to have all plugins I require in the JENKINS_HOME inside the image.
When running the image however we mount a single volume to the location of JENKINS_HOME as to persist all files in that location.
This obviously overlays the files of the image with the files on the volume. Classic problem.
Now: In "pure" Docker I was able to simply "re-mount" the plugin folder's location again (I won't go into detail to keep this a little shorter) to "pull it back up to the surface". Thus resulting in all files from the volume BUT the plugins folder from the image.
This functionality does not seem to work in Kubernetes anymore.
Thus I would like to change the directory in which Jenkins stores its plugins (when I install them during build time) so they won't be in JENKINS_HOME anymore and thus won't be "over-mounted" by the volume at runtime.
I am having a hard time finding a config value for the plugin directory. Is there one?

Dockerfile, how to COPY files from parent directory

I have folder with files common for multiple docker images. How can I COPY these files to the image referencing the parent directory in Dockerfile? Obviously I don't want to duplicate this folder to all Docker projects.
When you run docker build the latest parameter is called PATH. Here is a description of it taken from here:
The docker build command builds Docker images from a Dockerfile and a “context”. A build’s context is the set of files located in the specified PATH [omissis]. The build process can refer to any of the files in the context. For example, your build can use a COPY instruction to reference a file in the context.
That means you have to specify a PATH that contains all of the files you need in your Dockerfile. Please be aware that changing the PATH to a different directory will require changing all of your COPY and ADD instructions to reflect the new directory structure.

Jenkins with Copy Artifact plugin: copy directory contents with subdirectories

I have a structure of artifacts in another build:
/
/bundle/docs
/bundle/bin
/bundle/bin/scripts
I want to copy all files and sudirectories into the current job's workspace subfolder 'product1' from /bundle/bin. I expect to see in %WORKSAPCE%/product1 contents of /bundle/bin.
I've configured it like this:
Artifacts to copy: bundle/bin/**
But it creates %WORKSAPCE%/product1//bundle/bin instead.
Is it possible?
Seems like that's just how the plugin works. Your options are:
Keep the same configuration and manipulate directories later using sh mv (Linux) or cmd move (Windows) command. This is the workaround used in my environment.
Check the "Flatten directories" option (but this will mix together the /bundle/bin and /bundle/bin/scripts)
Improve the plugin and contribute your code to the community :-)

Docker - where are the src files for ADD and COPY?

I am trying to learn Docker from other DockerFiles and and set up a customised development environment for my projects.
But from other DockerFiles, I don't understand - where are those src files coming from for ADD and COPY? How do I create them myself? What code should I put inside them?
For instance, fauria/lamp:
COPY run-lamp.sh /usr/sbin/
Where can I get this file or create it? What are the lines inside that file?
again, nickistre/ubuntu-lamp:
ADD supervisord.conf /etc/
Where can I get a copy of it?
Another one, linuxconfig/lamp:
# Include supervisor configuration
ADD supervisor-lamp.conf /etc/supervisor/conf.d/
ADD supervisord.conf /etc/supervisor/
supervisor-lamp.conf and supervisord.conf?
Any ideas?
When you run a docker build ., files in the folder . that are not included inside the .dockerignore file are sent to the Docker engine. From this context of files, docker performs the COPY or ADD commands.
With your first example, the Dockerfile is located in a github repo (linked on the right side of the page on the Docker hub), and inside that repo is the run-lamp.sh script. Therefore if you're trying to reproduce the image, you would checkout the linked github repo and perform your build from within that folder.

Resources