docker icon indicating copy to clipboard operation
docker copied to clipboard

Override PLUGIN_DIR to match required location

Open nhojpatrick opened this issue 2 years ago • 3 comments

Following on from https://github.com/jenkinsci/docker/pull/1299 I've had to define the following to be able to use jenkins-plugin-cli. I could be doing this wrong but without specifying PLUGIN_DIR, the plugins all get downloaded, but they are then not enabled/activated.

FROM jenkins/jenkins:lts
ENV PLUGIN_DIR /var/jenkins_home/plugins
RUN jenkins-plugin-cli --plugins greenballs

As the default location is for not windows is /usr/share/jenkins/ref/plugins, which is not where these Dockerfiles appear to put plugins.

  • [x] Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • [x] Ensure that the pull request title represents the desired changelog entry
  • [x] Please describe what you did
  • [x] Link to relevant issues in GitHub or Jira
  • [x] Link to relevant pull requests, esp. upstream and downstream changes
  • [x] Ensure you have provided tests - that demonstrates feature works or fixes the issue

nhojpatrick avatar Mar 08 '22 20:03 nhojpatrick

Something appears to different about your environment than other environments. When I use the following Dockerfile (an excerpt of the "Installing Jenkins on Docker" page), it builds and runs as expected:

$ cat Dockerfile
FROM jenkins/jenkins:2.319.3
RUN jenkins-plugin-cli --plugins "blueocean:1.25.3 docker-workflow:1.28"
$ docker build -t my-jenkins:2.319.3 .
$ docker run --rm -i -p 8080:8080 -t my-jenkins:2.319.3

That two line Dockerfile installs and runs Jenkins 2.319.3 with Blue Ocean 1.25.3 and the Pipeline plugins.

I'm not sure what is different between my environment and yours. Any insights?

MarkEWaite avatar Mar 08 '22 21:03 MarkEWaite

So without PLUGIN_DIR I get the following;

#4 5.627 io.jenkins.tools.pluginmanager.impl.DownloadPluginException: Unable to move greenballs to the plugin directory
#4 5.628 	at io.jenkins.tools.pluginmanager.impl.PluginManager.downloadPlugins(PluginManager.java:609)
#4 5.628 	at io.jenkins.tools.pluginmanager.impl.PluginManager.start(PluginManager.java:226)
#4 5.628 	at io.jenkins.tools.pluginmanager.impl.PluginManager.start(PluginManager.java:172)
#4 5.629 	at io.jenkins.tools.pluginmanager.cli.Main.main(Main.java:70)
#4 5.630 Caused by: java.nio.file.AccessDeniedException: /tmp/plugin-installation-manager-downloads6541850274283243284/greenballs.jpi -> /usr/share/jenkins/ref/plugins/greenballs.jpi
#4 5.630 	at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:90)
#4 5.630 	at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
#4 5.630 	at java.base/sun.nio.fs.UnixCopyFile.move(UnixCopyFile.java:478)
#4 5.630 	at java.base/sun.nio.fs.UnixFileSystemProvider.move(UnixFileSystemProvider.java:267)
#4 5.631 	at java.base/java.nio.file.Files.move(Files.java:1422)
#4 5.631 	at io.jenkins.tools.pluginmanager.impl.PluginManager.downloadPlugins(PluginManager.java:604)
#4 5.631 	... 3 more
#4 5.632 Unable to move greenballs to the plugin directory

I'm trying to use local json files and jenkins mirror running in another docker container locally. So it would be linked to some of the other config I'm doing.

The plugins file, where should I put that as the example is saying /usr/share/jenkins/ref/plugins, should I be putting that in /var/jenkins_home/plugins?

nhojpatrick avatar Mar 09 '22 07:03 nhojpatrick

@MarkEWaite can you try the version below. My original still has issues and I think that was because I was using ENV keys that also had meaning by jenkins-plugin-cli, i.e. JENKINS_UPDATE_CENTER.

FROM jenkins/jenkins:lts
RUN curl -fsSL "https://updates.jenkins.io/update-center.json?version=2.319.3" -o /tmp/update-center.json
RUN curl -fsSL "https://updates.jenkins.io/experimental/update-center.json?version=2.319.3" -o /tmp/update-center.experimental.json
RUN curl -fsSL "https://updates.jenkins.io/plugin-versions.json" -o /tmp/plugin-versions.json
# FOLLOWING HAVE TO BE SET
ENV JENKINS_UC_DOWNLOAD_URL https://updates.jenkins.io/download/plugins
RUN jenkins-plugin-cli --verbose \
	--jenkins-update-center file:///tmp/update-center.json \
	--jenkins-experimental-update-center file:///tmp/update-center.experimental.json \
	--jenkins-plugin-info file:///tmp/plugin-versions.json \
	--plugins "greenballs"

So the 3 files downloaded are the 3 files listed.

Without JENKINS_UC_DOWNLOAD_URL specified I get this error;

#8 3.340 Will use url: file:/download/plugins/greenballs/1.15.1/greenballs.hpi to download greenballs plugin
#8 3.341 Downloaded file is not a valid ZIP
#8 3.343 java.nio.file.NoSuchFileException: /tmp/plugin-installation-manager-downloads11537169406230468740/greenballs.jpi

nhojpatrick avatar Mar 09 '22 09:03 nhojpatrick

Plugins get installed into /usr/share/ref/jenkins/plugins Then on boot, jenkins core copies /usr/share/ref/jenkins/plugins/* with non overwrite to $JENKINS_HOME/plugins/*

I think a better fix would be a config flag to allow the docker image to overwrite from ref, and/or docker image being able to delete plugins directory (like helm can) on startup.

Note, ENV PLUGIN_DIR /var/jenkins_home/plugins won't work for anyone who mounts /var/jenkins_home, which will override anything in the docker container.

halkeye avatar Sep 29 '22 16:09 halkeye

Using OpenShift mainly for Jenkins now and different plugin installation so don't care about this Docker based issue anymore

nhojpatrick avatar Oct 12 '22 20:10 nhojpatrick