Skip to content

Commit fc0053c

Browse files
MRamonLeonoleg-nenashev
authored andcommitted
#857 - Make the Jenkins WAR path configurable by the JENKINS_WAR env property (#873)
* [#857] Make the jenkins.war configurable by JENKINS_WAR env property * [#857] A final new line * [#857] Add env variables documentation and minor fixes * [#861] Merge documentation sections * [#861] Format default values
1 parent e090875 commit fc0053c

File tree

7 files changed

+74
-8
lines changed

7 files changed

+74
-8
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ tests/functions/copy_reference_file.log
66
manifest-tool
77
multiarch/qemu-*
88
multiarch/Dockerfile-*
9+
/docker.iml
10+
/.idea/

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ test-centos: prepare-test
5151

5252
test: test-debian test-alpine test-slim test-jdk11 test-centos
5353

54+
test-install-plugins: prepare-test
55+
DOCKERFILE=Dockerfile-alpine bats/bin/bats tests/install-plugins.bats
56+
5457
publish:
5558
./publish.sh ; \
5659
./publish.sh --variant alpine ; \

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ During the download, the script will use update centers defined by the following
183183
Defines Maven mirror to be used to download plugins from the
184184
[Incrementals repo](https://jenkins.io/blog/2018/05/15/incremental-deployment/).
185185
Default value: https://repo.jenkins-ci.org/incrementals
186-
186+
* `JENKINS_UC_DOWNLOAD` - Download url of the Update Center.
187+
Default value: `$JENKINS_UC/download`
188+
187189
It is possible to override the environment variables in images.
188190

189191
:exclamation: Note that changing this variables **will not** change the Update Center being used by Jenkins runtime.
@@ -207,6 +209,20 @@ There are also custom version specifiers:
207209
`mvn incrementals:updatePluginsTxt -DpluginsFile=plugins.txt`.
208210
[More Info](https://github.com/jenkinsci/incrementals-tools#updating-versions-for-jenkins-docker-images)
209211

212+
### Fine-tune the downloads
213+
214+
The script uses `curl` to download the plugins. You can configure the options with some environment variables:
215+
* `CURL_OPTIONS`: When downloading the plugins with curl. Curl options. Default value: `-sSfL`
216+
* `CURL_CONNECTION_TIMEOUT`: When downloading the plugins with curl. <seconds> Maximum time allowed for connection. Default value: `20`
217+
* `CURL_RETRY`: When downloading the plugins with curl. Retry request if transient problems occur. Default value: `3`
218+
* `CURL_RETRY_DELAY`: When downloading the plugins with curl. <seconds> Wait time between retries. Default value: `0`
219+
* `CURL_RETRY_MAX_TIME`: When downloading the plugins with curl. <seconds> Retry only within this period. Default value: `60`
220+
221+
### Other environment variables
222+
In case you have changed some default paths in the image, you can modify their values with these environment variables:
223+
* `REF`: directory with preinstalled plugins. Default value: `/usr/share/jenkins/ref/plugins`
224+
* `JENKINS_WAR`: full path to the jenkins.war. Default value: `/usr/share/jenkins/jenkins.war`
225+
210226
### Script usage
211227

212228
You can run the script manually in Dockerfile:

install-plugins.sh

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,27 @@
44
#
55
# FROM jenkins
66
# RUN install-plugins.sh docker-slaves github-branch-source
7+
#
8+
# Environment variables:
9+
# REF: directory with preinstalled plugins. Default: /usr/share/jenkins/ref/plugins
10+
# JENKINS_WAR: full path to the jenkins.war. Default: /usr/share/jenkins/jenkins.war
11+
# JENKINS_UC: url of the Update Center. Default: ""
12+
# JENKINS_UC_EXPERIMENTAL: url of the Experimental Update Center for experimental versions of plugins. Default: ""
13+
# JENKINS_INCREMENTALS_REPO_MIRROR: url of the incrementals repo mirror. Default: ""
14+
# JENKINS_UC_DOWNLOAD: download url of the Update Center. Default: JENKINS_UC/download
15+
# CURL_OPTIONS When downloading the plugins with curl. Curl options. Default: -sSfL
16+
# CURL_CONNECTION_TIMEOUT When downloading the plugins with curl. <seconds> Maximum time allowed for connection. Default: 20
17+
# CURL_RETRY When downloading the plugins with curl. Retry request if transient problems occur. Default: 3
18+
# CURL_RETRY_DELAY When downloading the plugins with curl. <seconds> Wait time between retries. Default: 0
19+
# CURL_RETRY_MAX_TIME When downloading the plugins with curl. <seconds> Retry only within this period. Default: 60
720

821
set -o pipefail
922

1023
REF_DIR=${REF:-/usr/share/jenkins/ref/plugins}
1124
FAILED="$REF_DIR/failed-plugins.txt"
1225

26+
JENKINS_WAR=${JENKINS_WAR:-/usr/share/jenkins/jenkins.war}
27+
1328
. /usr/local/bin/jenkins-support
1429

1530
getLockFile() {
@@ -147,11 +162,10 @@ resolveDependencies() {
147162
}
148163

149164
bundledPlugins() {
150-
local JENKINS_WAR=/usr/share/jenkins/jenkins.war
151-
if [ -f $JENKINS_WAR ]
165+
if [ -f "$JENKINS_WAR" ]
152166
then
153167
TEMP_PLUGIN_DIR=/tmp/plugintemp.$$
154-
for i in $(jar tf $JENKINS_WAR | grep -E '[^detached-]plugins.*\..pi' | sort)
168+
for i in $(jar tf "$JENKINS_WAR" | grep -E '[^detached-]plugins.*\..pi' | sort)
155169
do
156170
rm -fr $TEMP_PLUGIN_DIR
157171
mkdir -p $TEMP_PLUGIN_DIR
@@ -183,11 +197,9 @@ installedPlugins() {
183197
}
184198

185199
jenkinsMajorMinorVersion() {
186-
local JENKINS_WAR
187-
JENKINS_WAR=/usr/share/jenkins/jenkins.war
188200
if [[ -f "$JENKINS_WAR" ]]; then
189201
local version major minor
190-
version="$(java -jar $JENKINS_WAR --version)"
202+
version="$(java -jar "$JENKINS_WAR" --version)"
191203
major="$(echo "$version" | cut -d '.' -f 1)"
192204
minor="$(echo "$version" | cut -d '.' -f 2)"
193205
echo "$major.$minor"
@@ -224,7 +236,7 @@ main() {
224236
mkdir "$(getLockFile "${plugin%%:*}")"
225237
done
226238

227-
echo "Analyzing war..."
239+
echo "Analyzing war $JENKINS_WAR..."
228240
bundledPlugins="$(bundledPlugins)"
229241

230242
echo "Registering preinstalled plugins..."

tests/install-plugins.bats

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,15 @@ SUT_IMAGE=$(sut_image)
201201
run docker_build_child $SUT_IMAGE-install-plugins-no-war $BATS_TEST_DIRNAME/install-plugins/no-war
202202
assert_success
203203
}
204+
205+
@test "Use a custom jenkins.war" {
206+
# Build the image using the right Dockerfile setting a new war with JENKINS_WAR env and with a weird plugin inside
207+
run docker_build_child $SUT_IMAGE-install-plugins-custom-war $BATS_TEST_DIRNAME/install-plugins/custom-war --no-cache
208+
assert_success
209+
# Assert the weird plugin is there
210+
assert_output --partial 'my-happy-plugin:1.1'
211+
}
212+
213+
@test "clean work directory" {
214+
run bash -c "rm -rf $BATS_TEST_DIRNAME/custom-war/work-${SUT_IMAGE}"
215+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM bats-jenkins
2+
3+
# Define a custom location for the war
4+
ENV JENKINS_WAR /test-custom-dockerfile/my-custom-jenkins.war
5+
WORKDIR /test-custom-dockerfile
6+
# Add there a new weird plugin to assert
7+
COPY --chown=jenkins:jenkins WEB-INF/ WEB-INF/
8+
9+
USER root
10+
RUN chown jenkins:jenkins /test-custom-dockerfile
11+
USER jenkins
12+
13+
# Copy the original jenkins.war to the custom location
14+
RUN cp /usr/share/jenkins/jenkins.war $JENKINS_WAR && \
15+
chown jenkins:jenkins $JENKINS_WAR
16+
17+
# Add the weird plugin to the new custom war
18+
RUN jar -uf my-custom-jenkins.war WEB-INF/*
19+
20+
# Run the install-plugins.sh script
21+
RUN /usr/local/bin/install-plugins.sh maven-plugin:2.7.1
Binary file not shown.

0 commit comments

Comments
 (0)