Add plugin-installation-manager-tool

This commit is contained in:
Tim Jacomb 2020-07-27 22:10:24 +01:00
parent 2d875cc155
commit 4e86cfd72f
No known key found for this signature in database
GPG Key ID: D40F4AD2F55AF15F
21 changed files with 391 additions and 57 deletions

View File

@ -64,6 +64,9 @@ ENV JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental
ENV JENKINS_INCREMENTALS_REPO_MIRROR=https://repo.jenkins-ci.org/incrementals
RUN chown -R ${user} "$JENKINS_HOME" "$REF"
ARG PLUGIN_CLI_URL=https://github.com/timja/plugin-installation-manager-tool/releases/download/plugin-management-parent-pom-1.2.4-beta/jenkins-plugin-manager-1.2.1-SNAPSHOT.jar
RUN curl -fsSL ${PLUGIN_CLI_URL} -o /usr/lib/jenkins-plugin-manager.jar
# for main web interface:
EXPOSE ${http_port}
@ -77,6 +80,8 @@ USER ${user}
COPY jenkins-support /usr/local/bin/jenkins-support
COPY jenkins.sh /usr/local/bin/jenkins.sh
COPY tini-shim.sh /bin/tini
COPY jenkins-plugin-cli.sh /bin/jenkins-plugin-cli
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/jenkins.sh"]
# from a derived Dockerfile, can use `RUN plugins.sh active.txt` to setup ${REF}/plugins from a support bundle

View File

@ -62,6 +62,9 @@ ENV JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental
ENV JENKINS_INCREMENTALS_REPO_MIRROR=https://repo.jenkins-ci.org/incrementals
RUN chown -R ${user} "$JENKINS_HOME" "$REF"
ARG PLUGIN_CLI_URL=https://github.com/timja/plugin-installation-manager-tool/releases/download/plugin-management-parent-pom-1.2.4-beta/jenkins-plugin-manager-1.2.1-SNAPSHOT.jar
RUN curl -fsSL ${PLUGIN_CLI_URL} -o /usr/lib/jenkins-plugin-manager.jar
# for main web interface:
EXPOSE ${http_port}
@ -75,6 +78,8 @@ USER ${user}
COPY jenkins-support /usr/local/bin/jenkins-support
COPY jenkins.sh /usr/local/bin/jenkins.sh
COPY tini-shim.sh /bin/tini
COPY jenkins-plugin-cli.sh /bin/jenkins-plugin-cli
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/jenkins.sh"]
# from a derived Dockerfile, can use `RUN plugins.sh active.txt` to setup $REF/plugins from a support bundle

View File

@ -63,6 +63,9 @@ ENV JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental
ENV JENKINS_INCREMENTALS_REPO_MIRROR=https://repo.jenkins-ci.org/incrementals
RUN chown -R ${user} "$JENKINS_HOME" "$REF"
ARG PLUGIN_CLI_URL=https://github.com/timja/plugin-installation-manager-tool/releases/download/plugin-management-parent-pom-1.2.4-beta/jenkins-plugin-manager-1.2.1-SNAPSHOT.jar
RUN curl -fsSL ${PLUGIN_CLI_URL} -o /usr/lib/jenkins-plugin-manager.jar
# for main web interface:
EXPOSE ${http_port}
@ -76,6 +79,8 @@ USER ${user}
COPY jenkins-support /usr/local/bin/jenkins-support
COPY jenkins.sh /usr/local/bin/jenkins.sh
COPY tini-shim.sh /bin/tini
COPY jenkins-plugin-cli.sh /bin/jenkins-plugin-cli
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/jenkins.sh"]
# from a derived Dockerfile, can use `RUN plugins.sh active.txt` to setup $REF/plugins from a support bundle

View File

@ -63,6 +63,9 @@ ENV JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental
ENV JENKINS_INCREMENTALS_REPO_MIRROR=https://repo.jenkins-ci.org/incrementals
RUN chown -R ${user} "$JENKINS_HOME" "$REF"
ARG PLUGIN_CLI_URL=https://github.com/timja/plugin-installation-manager-tool/releases/download/plugin-management-parent-pom-1.2.4-beta/jenkins-plugin-manager-1.2.1-SNAPSHOT.jar
RUN curl -fsSL ${PLUGIN_CLI_URL} -o /usr/lib/jenkins-plugin-manager.jar
# for main web interface:
EXPOSE ${http_port}
@ -76,6 +79,8 @@ USER ${user}
COPY jenkins-support /usr/local/bin/jenkins-support
COPY jenkins.sh /usr/local/bin/jenkins.sh
COPY tini-shim.sh /bin/tini
COPY jenkins-plugin-cli.sh /bin/jenkins-plugin-cli
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/jenkins.sh"]
# from a derived Dockerfile, can use `RUN plugins.sh active.txt` to setup $REF/plugins from a support bundle

View File

@ -62,6 +62,9 @@ ENV JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental
ENV JENKINS_INCREMENTALS_REPO_MIRROR=https://repo.jenkins-ci.org/incrementals
RUN chown -R ${user} "$JENKINS_HOME" "$REF"
ARG PLUGIN_CLI_URL=https://github.com/timja/plugin-installation-manager-tool/releases/download/plugin-management-parent-pom-1.2.4-beta/jenkins-plugin-manager-1.2.1-SNAPSHOT.jar
RUN curl -fsSL ${PLUGIN_CLI_URL} -o /usr/lib/jenkins-plugin-manager.jar
# for main web interface:
EXPOSE ${http_port}
@ -76,6 +79,8 @@ USER ${user}
COPY jenkins-support /usr/local/bin/jenkins-support
COPY jenkins.sh /usr/local/bin/jenkins.sh
COPY tini-shim.sh /bin/tini
COPY jenkins-plugin-cli.sh /bin/jenkins-plugin-cli
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/jenkins.sh"]
# from a derived Dockerfile, can use `RUN plugins.sh active.txt` to setup $REF/plugins from a support bundle

View File

@ -66,6 +66,9 @@ ENV JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental
ENV JENKINS_INCREMENTALS_REPO_MIRROR=https://repo.jenkins-ci.org/incrementals
RUN chown -R ${user} "$JENKINS_HOME" "$REF"
ARG PLUGIN_CLI_URL=https://github.com/timja/plugin-installation-manager-tool/releases/download/plugin-management-parent-pom-1.2.4-beta/jenkins-plugin-manager-1.2.1-SNAPSHOT.jar
RUN curl -fsSL ${PLUGIN_CLI_URL} -o /usr/lib/jenkins-plugin-manager.jar
# for main web interface:
EXPOSE ${http_port}
@ -79,6 +82,7 @@ USER ${user}
COPY jenkins-support /usr/local/bin/jenkins-support
COPY jenkins.sh /usr/local/bin/jenkins.sh
COPY tini-shim.sh /bin/tini
COPY jenkins-plugin-cli.sh /bin/jenkins-plugin-cli
# set variables to create shared class cache
ENV JAVA_SCC_OPTS "-Xshareclasses:name=jenkins_scc,cacheDir=/tmp,enableBCI -Xscmx80M"

View File

@ -66,6 +66,9 @@ ENV JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental
ENV JENKINS_INCREMENTALS_REPO_MIRROR=https://repo.jenkins-ci.org/incrementals
RUN chown -R ${user} "$JENKINS_HOME" "$REF"
ARG PLUGIN_CLI_URL=https://github.com/timja/plugin-installation-manager-tool/releases/download/plugin-management-parent-pom-1.2.4-beta/jenkins-plugin-manager-1.2.1-SNAPSHOT.jar
RUN curl -fsSL ${PLUGIN_CLI_URL} -o /usr/lib/jenkins-plugin-manager.jar
# for main web interface:
EXPOSE ${http_port}
@ -79,6 +82,7 @@ USER ${user}
COPY jenkins-support /usr/local/bin/jenkins-support
COPY jenkins.sh /usr/local/bin/jenkins.sh
COPY tini-shim.sh /bin/tini
COPY jenkins-plugin-cli.sh /bin/jenkins-plugin-cli
# set variables to create shared class cache
ENV JAVA_SCC_OPTS "-Xshareclasses:name=jenkins_scc,cacheDir=/tmp,enableBCI -Xscmx80M"

View File

@ -64,6 +64,9 @@ ENV JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental
ENV JENKINS_INCREMENTALS_REPO_MIRROR=https://repo.jenkins-ci.org/incrementals
RUN chown -R ${user} "$JENKINS_HOME" "$REF"
ARG PLUGIN_CLI_URL=https://github.com/timja/plugin-installation-manager-tool/releases/download/plugin-management-parent-pom-1.2.4-beta/jenkins-plugin-manager-1.2.1-SNAPSHOT.jar
RUN curl -fsSL ${PLUGIN_CLI_URL} -o /usr/lib/jenkins-plugin-manager.jar
# for main web interface:
EXPOSE ${http_port}
@ -77,6 +80,8 @@ USER ${user}
COPY jenkins-support /usr/local/bin/jenkins-support
COPY jenkins.sh /usr/local/bin/jenkins.sh
COPY tini-shim.sh /bin/tini
COPY jenkins-plugin-cli.sh /bin/jenkins-plugin-cli
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/jenkins.sh"]
# from a derived Dockerfile, can use `RUN plugins.sh active.txt` to setup $REF/plugins from a support bundle

View File

@ -69,7 +69,7 @@ test-openj9-jdk11:
test: test-debian test-alpine test-slim test-jdk11 test-centos test-centos7 test-openj9 test-openj9-jdk11
test-install-plugins: prepare-test
DOCKERFILE=Dockerfile-alpine bats/bin/bats tests/install-plugins.bats
DOCKERFILE=Dockerfile-alpine bats/bin/bats tests/install-plugins-plugins-cli.bats
publish:
./publish.sh ; \

View File

@ -166,70 +166,21 @@ COPY custom.groovy /usr/share/jenkins/ref/init.groovy.d/custom.groovy
## Preinstalling plugins
You can rely on the `install-plugins.sh` script to pass a set of plugins to download with their dependencies.
You can rely on the `jenkins-plugin-cli` script to pass a set of plugins to download with their dependencies.
This script will perform downloads from update centers, and internet access is required for the default update centers.
### Setting update centers
During the download, the script will use update centers defined by the following environment variables:
* `JENKINS_UC` - Main update center.
This update center may offer plugin versions depending on the Jenkins LTS Core versions.
Default value: https://updates.jenkins.io
* `JENKINS_UC_EXPERIMENTAL` - [Experimental Update Center](https://jenkins.io/blog/2013/09/23/experimental-plugins-update-center/).
This center offers Alpha and Beta versions of plugins.
Default value: https://updates.jenkins.io/experimental
* `JENKINS_INCREMENTALS_REPO_MIRROR` -
Defines Maven mirror to be used to download plugins from the
[Incrementals repo](https://jenkins.io/blog/2018/05/15/incremental-deployment/).
Default value: https://repo.jenkins-ci.org/incrementals
* `JENKINS_UC_DOWNLOAD` - Download url of the Update Center.
Default value: `$JENKINS_UC/download`
See the CLI's [documentation](https://github.com/jenkinsci/plugin-installation-manager-tool) for more information,
or run `jenkins-plugin-cli --help` to see the available options.
It is possible to override the environment variables in images.
:exclamation: Note that changing this variables **will not** change the Update Center being used by Jenkins runtime.
### Plugin version format
Use plugin artifact ID, without `-plugin` extension, and append the version if needed separated by `:`.
Dependencies that are already included in the Jenkins war will only be downloaded if their required version is newer than the one included.
There are also custom version specifiers:
* `latest` - download the latest version from the main update center.
For Jenkins LTS images
(example: `git:latest`)
* `experimental` - download the latest version from the experimental update center defined by the `JENKINS_UC_EXPERIMENTAL` environment variable (example: `filesystem_scm:experimental`)
* `incrementals;org.jenkins-ci.plugins.workflow;2.19-rc289.d09828a05a74[;githubUserId][;branchName]`
- download the plugin from the [Incrementals repo](https://jenkins.io/blog/2018/05/15/incremental-deployment/).
* For this option you need to specify `groupId` of the plugin.
Note that this value may change between plugin versions without notice.
* In order to automatically update Incrementals in plugins.txt, it is possible to use the Incrementals Maven Plugin:
`mvn incrementals:updatePluginsTxt -DpluginsFile=plugins.txt`.
[More Info](https://github.com/jenkinsci/incrementals-tools#updating-versions-for-jenkins-docker-images)
### Fine-tune the downloads
The script uses `curl` to download the plugins. You can configure the options with some environment variables:
* `CURL_OPTIONS`: When downloading the plugins with curl. Curl options. Default value: `-sSfL`
* `CURL_CONNECTION_TIMEOUT`: When downloading the plugins with curl. <seconds> Maximum time allowed for connection. Default value: `20`
* `CURL_RETRY`: When downloading the plugins with curl. Retry request if transient problems occur. Default value: `3`
* `CURL_RETRY_DELAY`: When downloading the plugins with curl. <seconds> Wait time between retries. Default value: `0`
* `CURL_RETRY_MAX_TIME`: When downloading the plugins with curl. <seconds> Retry only within this period. Default value: `60`
### Other environment variables
In case you have changed some default paths in the image, you can modify their values with these environment variables:
* `REF`: directory with preinstalled plugins. Default value: `/usr/share/jenkins/ref/plugins`
* `JENKINS_WAR`: full path to the jenkins.war. Default value: `/usr/share/jenkins/jenkins.war`
:exclamation: Note that changing update center variables **will not** change the Update Center being used by Jenkins runtime.
### Script usage
You can run the script manually in Dockerfile:
You can run the CLI manually in Dockerfile:
```Dockerfile
FROM jenkins/jenkins:lts
RUN /usr/local/bin/install-plugins.sh docker-slaves github-branch-source:1.8
RUN jenkins-plugin-cli --plugins docker-slaves github-branch-source:1.8
```
Furthermore it is possible to pass a file that contains this set of plugins (with or without line breaks).
@ -237,7 +188,7 @@ Furthermore it is possible to pass a file that contains this set of plugins (wit
```Dockerfile
FROM jenkins/jenkins:lts
COPY plugins.txt /usr/share/jenkins/ref/plugins.txt
RUN /usr/local/bin/install-plugins.sh < /usr/share/jenkins/ref/plugins.txt
RUN jenkins-plugin-cli -f /usr/share/jenkins/ref/plugins.txt
```
When jenkins container starts, it will check `JENKINS_HOME` has this reference content, and copy them
@ -275,6 +226,18 @@ to indicate that this Jenkins installation is fully configured.
Otherwise a banner will appear prompting the user to install additional plugins,
which may be inappropriate.
### Updating plugins file
The [plugin-installation-manager-tool](https://github.com/jenkinsci/plugin-installation-manager-tool) supports updating the plugin file for you.
Example command:
```command
JENKINS_IMAGE=jenkins/jenkins
docker run -it ${JENKINS_IMAGE} bash -c "stty -onlcr && jenkins-plugin-cli -f /usr/share/jenkins/ref/plugins.txt --available-updates --output txt" > plugins2.txt
mv plugins2.txt plugins.txt
```
# Upgrading
All the data needed is in the /var/jenkins_home directory - so depending on how you manage that - depends on how you upgrade. Generally - you can copy it out - and then "docker pull" the image again - and you will have the latest LTS - you can then start up with -v pointing to that data (/var/jenkins_home) and everything will be as you left it.

6
jenkins-plugin-cli.sh Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env bash
JENKINS_UC=https://updates.jenkins.io/update-center.actual.json
JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental/update-center.actual.json
java -jar /usr/lib/jenkins-plugin-manager.jar "$@"

View File

@ -0,0 +1,235 @@
#!/usr/bin/env bats
load 'test_helper/bats-support/load'
load 'test_helper/bats-assert/load'
load test_helpers
SUT_IMAGE=$(sut_image)
@test "build image" {
cd $BATS_TEST_DIRNAME/..
docker_build -t $SUT_IMAGE .
}
@test "plugins are installed with jenkins-plugin-cli" {
run docker_build_child $SUT_IMAGE-install-plugins $BATS_TEST_DIRNAME/install-plugins
assert_success
refute_line --partial 'Skipping already installed dependency'
# replace DOS line endings \r\n
run bash -c "docker run --rm $SUT_IMAGE-install-plugins ls --color=never -1 /var/jenkins_home/plugins | tr -d '\r'"
assert_success
assert_line 'junit.jpi'
assert_line 'junit.jpi.pinned'
assert_line 'ant.jpi'
assert_line 'ant.jpi.pinned'
assert_line 'credentials.jpi'
assert_line 'credentials.jpi.pinned'
assert_line 'mesos.jpi'
assert_line 'mesos.jpi.pinned'
# optional dependencies
refute_line 'metrics.jpi'
refute_line 'metrics.jpi.pinned'
# plugins bundled but under detached-plugins, so need to be installed
assert_line 'mailer.jpi'
assert_line 'mailer.jpi.pinned'
assert_line 'git.jpi'
assert_line 'git.jpi.pinned'
assert_line 'filesystem_scm.jpi'
assert_line 'filesystem_scm.jpi.pinned'
assert_line 'docker-plugin.jpi'
assert_line 'docker-plugin.jpi.pinned'
}
@test "plugins are installed with jenkins-plugin-cli with non-default REF" {
run docker_build_child $SUT_IMAGE-install-plugins-ref $BATS_TEST_DIRNAME/install-plugins/ref
assert_success
refute_line --partial 'Skipping already installed dependency'
docker run --rm $SUT_IMAGE-install-plugins-ref -e REF=/var/lib/jenkins/ref ls --color=never -1 /var/lib/jenkins/ref | tr -d '\r'
# replace DOS line endings \r\n
run bash -c "docker run --rm $SUT_IMAGE-install-plugins ls --color=never -1 /var/jenkins_home/plugins | tr -d '\r'"
assert_success
assert_line 'junit.jpi'
assert_line 'junit.jpi.pinned'
assert_line 'ant.jpi'
assert_line 'ant.jpi.pinned'
assert_line 'credentials.jpi'
assert_line 'credentials.jpi.pinned'
assert_line 'mesos.jpi'
assert_line 'mesos.jpi.pinned'
# optional dependencies
refute_line 'metrics.jpi'
refute_line 'metrics.jpi.pinned'
# plugins bundled but under detached-plugins, so need to be installed
assert_line 'mailer.jpi'
assert_line 'mailer.jpi.pinned'
assert_line 'git.jpi'
assert_line 'git.jpi.pinned'
assert_line 'filesystem_scm.jpi'
assert_line 'filesystem_scm.jpi.pinned'
assert_line 'docker-plugin.jpi'
assert_line 'docker-plugin.jpi.pinned'
}
@test "plugins are installed with jenkins-plugin-cli from a plugins file" {
run docker_build_child $SUT_IMAGE-install-plugins $BATS_TEST_DIRNAME/install-plugins
assert_success
run docker_build_child $SUT_IMAGE-install-plugins-pluginsfile $BATS_TEST_DIRNAME/install-plugins/pluginsfile
assert_success
refute_line --partial 'Skipping already installed dependency'
# replace DOS line endings \r\n
run bash -c "docker run --rm $SUT_IMAGE-install-plugins ls --color=never -1 /var/jenkins_home/plugins | tr -d '\r'"
assert_success
assert_line 'junit.jpi'
assert_line 'junit.jpi.pinned'
assert_line 'ant.jpi'
assert_line 'ant.jpi.pinned'
assert_line 'credentials.jpi'
assert_line 'credentials.jpi.pinned'
assert_line 'mesos.jpi'
assert_line 'mesos.jpi.pinned'
# optional dependencies
refute_line 'metrics.jpi'
refute_line 'metrics.jpi.pinned'
# plugins bundled but under detached-plugins, so need to be installed
assert_line 'mailer.jpi'
assert_line 'mailer.jpi.pinned'
assert_line 'git.jpi'
assert_line 'git.jpi.pinned'
assert_line 'filesystem_scm.jpi'
assert_line 'filesystem_scm.jpi.pinned'
}
@test "plugins are installed with jenkins-plugin-cli even when already exist" {
run docker_build_child $SUT_IMAGE-install-plugins $BATS_TEST_DIRNAME/install-plugins
assert_success
run docker_build_child $SUT_IMAGE-install-plugins-update $BATS_TEST_DIRNAME/install-plugins/update --no-cache
assert_success
assert_line --partial 'Skipping already installed dependency workflow-step-api'
assert_line "Using provided plugin: ant"
# replace DOS line endings \r\n
run bash -c "docker run --rm $SUT_IMAGE-install-plugins-update unzip -p /var/jenkins_home/plugins/junit.jpi META-INF/MANIFEST.MF | tr -d '\r'"
assert_success
assert_line 'Plugin-Version: 1.28'
}
@test "clean work directory" {
run bash -c "ls -la $BATS_TEST_DIRNAME/upgrade-plugins ; rm -rf $BATS_TEST_DIRNAME/upgrade-plugins/work-${SUT_IMAGE}"
assert_success
}
@test "plugins are getting upgraded but not downgraded" {
# Initial execution
run docker_build_child $SUT_IMAGE-install-plugins $BATS_TEST_DIRNAME/install-plugins
assert_success
local work; work="$BATS_TEST_DIRNAME/upgrade-plugins/work-${SUT_IMAGE}"
mkdir -p $work
# Image contains junit 1.6 and ant-plugin 1.3
run bash -c "docker run -u $UID -v $work:/var/jenkins_home --rm $SUT_IMAGE-install-plugins true"
assert_success
run unzip_manifest junit.jpi $work
assert_line 'Plugin-Version: 1.6'
run unzip_manifest ant.jpi $work
assert_line 'Plugin-Version: 1.3'
# Upgrade to new image with different plugins
run docker_build_child $SUT_IMAGE-upgrade-plugins $BATS_TEST_DIRNAME/upgrade-plugins
assert_success
# Images contains junit 1.28 and ant-plugin 1.2
run bash -c "docker run -u $UID -v $work:/var/jenkins_home --rm $SUT_IMAGE-upgrade-plugins true"
assert_success
run unzip_manifest junit.jpi $work
assert_success
# Should be updated
assert_line 'Plugin-Version: 1.28'
run unzip_manifest ant.jpi $work
# 1.2 is older than the existing 1.3, so keep 1.3
assert_line 'Plugin-Version: 1.3'
}
@test "clean work directory" {
run bash -c "ls -la $BATS_TEST_DIRNAME/upgrade-plugins ; rm -rf $BATS_TEST_DIRNAME/upgrade-plugins/work-${SUT_IMAGE}"
assert_success
}
@test "do not upgrade if plugin has been manually updated" {
run docker_build_child $SUT_IMAGE-install-plugins $BATS_TEST_DIRNAME/install-plugins
assert_success
local work; work="$BATS_TEST_DIRNAME/upgrade-plugins/work-${SUT_IMAGE}"
mkdir -p $work
# Image contains junit 1.6 and ant-plugin 1.3
run bash -c "docker run -u $UID -v $work:/var/jenkins_home --rm $SUT_IMAGE-install-plugins curl --connect-timeout 20 --retry 5 --retry-delay 0 --retry-max-time 60 -s -f -L https://updates.jenkins.io/download/plugins/junit/1.8/junit.hpi -o /var/jenkins_home/plugins/junit.jpi"
assert_success
run unzip_manifest junit.jpi $work
assert_line 'Plugin-Version: 1.8'
run docker_build_child $SUT_IMAGE-upgrade-plugins $BATS_TEST_DIRNAME/upgrade-plugins
assert_success
# Images contains junit 1.28 and ant-plugin 1.2
run bash -c "docker run -u $UID -v $work:/var/jenkins_home --rm $SUT_IMAGE-upgrade-plugins true"
assert_success
# junit shouldn't be upgraded
run unzip_manifest junit.jpi $work
assert_success
assert_line 'Plugin-Version: 1.8'
refute_line 'Plugin-Version: 1.28'
# ant shouldn't be downgraded
run unzip_manifest ant.jpi $work
assert_success
assert_line 'Plugin-Version: 1.3'
refute_line 'Plugin-Version: 1.2'
}
@test "clean work directory" {
run bash -c "ls -la $BATS_TEST_DIRNAME/upgrade-plugins ; rm -rf $BATS_TEST_DIRNAME/upgrade-plugins/work-${SUT_IMAGE}"
assert_success
}
@test "upgrade plugin even if it has been manually updated when PLUGINS_FORCE_UPGRADE=true" {
run docker_build_child $SUT_IMAGE-install-plugins $BATS_TEST_DIRNAME/install-plugins
assert_success
local work; work="$BATS_TEST_DIRNAME/upgrade-plugins/work-${SUT_IMAGE}"
mkdir -p $work
# Image contains junit 1.6 and ant-plugin 1.3
run bash -c "docker run -u $UID -v $work:/var/jenkins_home --rm $SUT_IMAGE-install-plugins curl --connect-timeout 20 --retry 5 --retry-delay 0 --retry-max-time 60 -s -f -L https://updates.jenkins.io/download/plugins/junit/1.8/junit.hpi -o /var/jenkins_home/plugins/junit.jpi"
assert_success
run unzip_manifest junit.jpi $work
assert_line 'Plugin-Version: 1.8'
run docker_build_child $SUT_IMAGE-upgrade-plugins $BATS_TEST_DIRNAME/upgrade-plugins
assert_success
# Images contains junit 1.28 and ant-plugin 1.2
run bash -c "docker run -e PLUGINS_FORCE_UPGRADE=true -u $UID -v $work:/var/jenkins_home --rm $SUT_IMAGE-upgrade-plugins true"
assert_success
# junit should be upgraded
run unzip_manifest junit.jpi $work
assert_success
refute_line 'Plugin-Version: 1.8'
assert_line 'Plugin-Version: 1.28'
# ant shouldn't be downgraded
run unzip_manifest ant.jpi $work
assert_success
assert_line 'Plugin-Version: 1.3'
refute_line 'Plugin-Version: 1.2'
}
@test "clean work directory" {
run bash -c "ls -la $BATS_TEST_DIRNAME/upgrade-plugins ; rm -rf $BATS_TEST_DIRNAME/upgrade-plugins/work-${SUT_IMAGE}"
assert_success
}
@test "plugins are installed with jenkins-plugin-cli and no war" {
run docker_build_child $SUT_IMAGE-install-plugins-no-war $BATS_TEST_DIRNAME/install-plugins/no-war
assert_success
}
@test "Use a custom jenkins.war" {
# Build the image using the right Dockerfile setting a new war with JENKINS_WAR env and with a weird plugin inside
run docker_build_child $SUT_IMAGE-install-plugins-custom-war $BATS_TEST_DIRNAME/install-plugins/custom-war --no-cache
assert_success
# Assert the weird plugin is there
assert_output --partial 'my-happy-plugin:1.1'
}
@test "clean work directory" {
run bash -c "ls -la $BATS_TEST_DIRNAME/upgrade-plugins ; rm -rf $BATS_TEST_DIRNAME/upgrade-plugins/work-${SUT_IMAGE}"
assert_success
}

View File

@ -0,0 +1,3 @@
FROM bats-jenkins
RUN /usr/local/bin/install-plugins.sh junit:1.6 ant:1.3 mesos:0.13.0 git:latest filesystem_scm:experimental docker:1.1.6

View File

@ -0,0 +1,21 @@
FROM bats-jenkins
# Define a custom location for the war
ENV JENKINS_WAR /test-custom-dockerfile/my-custom-jenkins.war
WORKDIR /test-custom-dockerfile
# Add there a new weird plugin to assert
COPY --chown=jenkins:jenkins WEB-INF/ WEB-INF/
USER root
RUN chown jenkins:jenkins /test-custom-dockerfile
USER jenkins
# Copy the original jenkins.war to the custom location
RUN cp /usr/share/jenkins/jenkins.war $JENKINS_WAR && \
chown jenkins:jenkins $JENKINS_WAR
# Add the weird plugin to the new custom war
RUN jar -uf my-custom-jenkins.war WEB-INF/*
# Run the install-plugins.sh script
RUN jenkins-plugin-cli --plugins junit:1.6

View File

@ -0,0 +1,7 @@
FROM bats-jenkins
COPY plugins.txt /usr/share/jenkins/ref/plugins.txt
USER root
RUN rm -rf /usr/share/jenkins/jenkins.war
USER jenkins
RUN jenkins-plugin-cli -f /usr/share/jenkins/ref/plugins.txt

View File

@ -0,0 +1,24 @@
# comment line should be skipped
# simple case
ant:1.3
# trailing spaces
junit:1.6
# leading spaces
mesos:0.13.0
# leading spaces, and trailing spaces
git:latest
# with comments at the end
filesystem_scm:experimental # comment at the end
# empty line
#
# empty line
# Incrementals (JENKINS-52028)
workflow-support:incrementals;org.jenkins-ci.plugins.workflow;2.19-rc289.d09828a05a74

View File

@ -0,0 +1,4 @@
FROM bats-jenkins
COPY plugins.txt /usr/share/jenkins/ref/plugins.txt
RUN jenkins-plugin-cli -f /usr/share/jenkins/ref/plugins.txt

View File

@ -0,0 +1,27 @@
# comment line should be skipped
# simple case
ant:1.3
# trailing spaces
junit:1.6
# leading spaces
mesos:0.13.0
# leading spaces, and trailing spaces
git:latest
# with comments at the end
filesystem_scm:experimental # comment at the end
# empty line
#
# empty line
# Incrementals (JENKINS-52028)
workflow-support:incrementals;org.jenkins-ci.plugins.workflow;2.19-rc289.d09828a05a74
# from url
subversion:::https://updates.jenkins.io/download/plugins/subversion/2.12.1/subversion.hpi

View File

@ -0,0 +1,3 @@
FROM bats-jenkins-install-plugins
RUN rm -rf /usr/share/jenkins/ref ; jenkins-plugin-cli --plugins junit:1.28 ant:1.3

View File

@ -0,0 +1,3 @@
FROM bats-jenkins-install-plugins
RUN jenkins-plugin-cli --plugins junit:1.28 ant:1.3