From 8b5649110cab53dd6ab4da898c416fcd5a5a58d0 Mon Sep 17 00:00:00 2001 From: Jonas Linde Date: Wed, 23 Aug 2017 17:06:01 +0200 Subject: [PATCH 01/11] Issue #559 - Do not reinstall already installed plugins --- install-plugins.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/install-plugins.sh b/install-plugins.sh index 10031b4..3b44ec7 100755 --- a/install-plugins.sh +++ b/install-plugins.sh @@ -111,7 +111,7 @@ resolveDependencies() { echo "Skipping optional dependency $plugin" else local pluginInstalled - if pluginInstalled="$(echo "${bundledPlugins}" | grep "^${plugin}:")"; then + if pluginInstalled="$(echo -e "${bundledPlugins}\n${installedPlugins}" | grep "^${plugin}:")"; then pluginInstalled="${pluginInstalled//[$'\r']}" local versionInstalled; versionInstalled=$(versionFromPlugin "${pluginInstalled}") local minVersion; minVersion=$(versionFromPlugin "${d}") @@ -119,7 +119,7 @@ resolveDependencies() { echo "Upgrading bundled dependency $d ($minVersion > $versionInstalled)" download "$plugin" & else - echo "Skipping already bundled dependency $d ($minVersion <= $versionInstalled)" + echo "Skipping already installed dependency $d ($minVersion <= $versionInstalled)" fi else download "$plugin" & @@ -206,6 +206,9 @@ main() { echo "Analyzing war..." bundledPlugins="$(bundledPlugins)" + echo "Registering preinstalled plugins..." + installedPlugins="$(installedPlugins)" + # Check if there's a version-specific update center, which is the case for LTS versions jenkinsVersion="$(jenkinsMajorMinorVersion)" if curl -fsL -o /dev/null "$JENKINS_UC/$jenkinsVersion"; then From 542fcdc558c1961d32214447b638518f96d8d0aa Mon Sep 17 00:00:00 2001 From: Clo Date: Mon, 9 Oct 2017 13:38:31 +0200 Subject: [PATCH 02/11] Consider non empty last line of plugins.txt --- install-plugins.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-plugins.sh b/install-plugins.sh index 10031b4..db5c314 100755 --- a/install-plugins.sh +++ b/install-plugins.sh @@ -190,7 +190,7 @@ main() { # Read plugins from stdin or from the command line arguments if [[ ($# -eq 0) ]]; then - while read -r line; do + while read -r line || [ "$line" != "" ]; do plugins+=("${line}") done else From e98947e4ad9eb6e7256f685e9a0dbd2d8cf398e8 Mon Sep 17 00:00:00 2001 From: Jonas Linde Date: Mon, 9 Oct 2017 15:41:09 +0200 Subject: [PATCH 03/11] Adds test case for not reinstalling dependencies --- tests/install-plugins.bats | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/install-plugins.bats b/tests/install-plugins.bats index a702d86..1a246b8 100644 --- a/tests/install-plugins.bats +++ b/tests/install-plugins.bats @@ -26,7 +26,7 @@ load test_helpers @test "plugins are installed with install-plugins.sh" { run docker build -t $SUT_IMAGE-install-plugins $BATS_TEST_DIRNAME/install-plugins assert_success - refute_line --partial 'Skipping already bundled dependency' + 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 @@ -55,7 +55,7 @@ load test_helpers @test "plugins are installed with install-plugins.sh from a plugins file" { run docker build -t $SUT_IMAGE-install-plugins-pluginsfile $BATS_TEST_DIRNAME/install-plugins/pluginsfile assert_success - refute_line --partial 'Skipping already bundled dependency' + 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 @@ -85,13 +85,18 @@ load test_helpers run docker build -t $SUT_IMAGE-install-plugins-update --no-cache $BATS_TEST_DIRNAME/install-plugins/update assert_success assert_line "Using provided plugin: ant" - refute_line --partial 'Skipping already bundled dependency' # replace DOS line endings \r\n run bash -c "docker run --rm $SUT_IMAGE-install-plugins-update unzip -p /var/jenkins_home/plugins/maven-plugin.jpi META-INF/MANIFEST.MF | tr -d '\r'" assert_success assert_line 'Plugin-Version: 2.13' } +@test "dependencies are not installed with install-plugins.sh when they already exist" { + run docker build -t $SUT_IMAGE-install-plugins-update --no-cache $BATS_TEST_DIRNAME/install-plugins/update + assert_success + assert_line --partial 'Skipping already installed dependency' +} + @test "plugins are getting upgraded but not downgraded" { # Initial execution run docker build -t $SUT_IMAGE-install-plugins $BATS_TEST_DIRNAME/install-plugins From 4b4faa8fa329ef908f352c23d4f84367aa81950c Mon Sep 17 00:00:00 2001 From: Jonas Linde Date: Mon, 9 Oct 2017 15:52:04 +0200 Subject: [PATCH 04/11] Simplifies test case for not reinstalling dependencies --- tests/install-plugins.bats | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/install-plugins.bats b/tests/install-plugins.bats index 1a246b8..8de2f99 100644 --- a/tests/install-plugins.bats +++ b/tests/install-plugins.bats @@ -84,6 +84,7 @@ load test_helpers @test "plugins are installed with install-plugins.sh even when already exist" { run docker build -t $SUT_IMAGE-install-plugins-update --no-cache $BATS_TEST_DIRNAME/install-plugins/update assert_success + assert_line --partial 'Skipping already installed dependency' 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/maven-plugin.jpi META-INF/MANIFEST.MF | tr -d '\r'" @@ -91,12 +92,6 @@ load test_helpers assert_line 'Plugin-Version: 2.13' } -@test "dependencies are not installed with install-plugins.sh when they already exist" { - run docker build -t $SUT_IMAGE-install-plugins-update --no-cache $BATS_TEST_DIRNAME/install-plugins/update - assert_success - assert_line --partial 'Skipping already installed dependency' -} - @test "plugins are getting upgraded but not downgraded" { # Initial execution run docker build -t $SUT_IMAGE-install-plugins $BATS_TEST_DIRNAME/install-plugins From 34d433aa41aa702fdc77f6cb9244a8d21f878496 Mon Sep 17 00:00:00 2001 From: Jonas Linde Date: Thu, 12 Oct 2017 14:02:36 +0200 Subject: [PATCH 05/11] Clarifying test case for not reinstalling dependencies --- tests/install-plugins.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/install-plugins.bats b/tests/install-plugins.bats index 8de2f99..938888f 100644 --- a/tests/install-plugins.bats +++ b/tests/install-plugins.bats @@ -84,7 +84,7 @@ load test_helpers @test "plugins are installed with install-plugins.sh even when already exist" { run docker build -t $SUT_IMAGE-install-plugins-update --no-cache $BATS_TEST_DIRNAME/install-plugins/update assert_success - assert_line --partial 'Skipping already installed dependency' + assert_line --partial 'Skipping already installed dependency javadoc' 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/maven-plugin.jpi META-INF/MANIFEST.MF | tr -d '\r'" From 79a039378c3e122675eeb33912fe40a78c427e3a Mon Sep 17 00:00:00 2001 From: Daniel Beck Date: Thu, 12 Oct 2017 21:38:15 +0200 Subject: [PATCH 06/11] Retrieve sha256 checksum for war file from Maven repo --- publish.sh | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/publish.sh b/publish.sh index f1c5945..5ae5ebb 100755 --- a/publish.sh +++ b/publish.sh @@ -85,12 +85,7 @@ publish() { build_opts=() fi - local dir=war - # lts is in a different dir - if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - dir=war-stable - fi - sha=$(curl -q -fsSL "http://mirrors.jenkins.io/${dir}/${version}/jenkins.war.sha256" | cut -d' ' -f 1) + sha=$(curl -q -fsSL "https://repo.jenkins-ci.org/releases/org/jenkins-ci/main/jenkins-war/${version}/jenkins-war-${version}.war.sha256" ) docker build --file "Dockerfile$variant" \ --build-arg "JENKINS_VERSION=$version" \ From e7a6f2c27007260d2b4c48928f85e65400bb6345 Mon Sep 17 00:00:00 2001 From: Daniel Beck Date: Mon, 6 Nov 2017 14:22:21 +0100 Subject: [PATCH 07/11] Run this every six hours --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f42d95e..118c7a0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,8 +1,8 @@ #!/usr/bin/env groovy properties([ - buildDiscarder(logRotator(numToKeepStr: '5', artifactNumToKeepStr: '5')), - pipelineTriggers([cron('@daily')]), + buildDiscarder(logRotator(numToKeepStr: '50', artifactNumToKeepStr: '5')), + pipelineTriggers([cron('H/6 * * * *')]), ]) node('docker') { From 95e322166fabce448cd9a5188ef3d8da7bcde763 Mon Sep 17 00:00:00 2001 From: Daniel Beck Date: Wed, 8 Nov 2017 11:45:39 +0100 Subject: [PATCH 08/11] Every six hours, for real this time --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 118c7a0..f2620fc 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,7 +2,7 @@ properties([ buildDiscarder(logRotator(numToKeepStr: '50', artifactNumToKeepStr: '5')), - pipelineTriggers([cron('H/6 * * * *')]), + pipelineTriggers([cron('H H/6 * * *')]), ]) node('docker') { From e00844fb7e14326d3895d61cc783369dc7709acf Mon Sep 17 00:00:00 2001 From: Marcel Cutts Date: Fri, 1 Dec 2017 13:06:49 +0100 Subject: [PATCH 09/11] Tiny grammar update "An" doesn't make sense here grammatically. One could say, "An internet connection", I believe, but I feel "and" is less structurally complex while still conveying the core message of, "Make sure you have internet.". --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f40e375..ec24157 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ 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. -This script will perform downloads from update centers, an internet access is required for the default update centers. +This script will perform downloads from update centers, and internet access is required for the default update centers. ### Setting update centers From e12444cf8e936ac923e3cee9ff7cb7090874591f Mon Sep 17 00:00:00 2001 From: Carlos Sanchez Date: Tue, 5 Dec 2017 08:28:53 -0600 Subject: [PATCH 10/11] Upgrade alpine to 3.7 and openjdk 8u151 --- Dockerfile-alpine | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Dockerfile-alpine b/Dockerfile-alpine index 669b347..513f160 100644 --- a/Dockerfile-alpine +++ b/Dockerfile-alpine @@ -1,5 +1,4 @@ -# DO NOT UPGRADE alpine until https://github.com/jenkinsci/docker/issues/508 is fixed -FROM openjdk:8u121-jdk-alpine +FROM openjdk:8-jdk-alpine RUN apk add --no-cache git openssh-client curl unzip bash ttf-dejavu coreutils @@ -14,24 +13,24 @@ ENV JENKINS_HOME /var/jenkins_home ENV JENKINS_SLAVE_AGENT_PORT ${agent_port} # Jenkins is run with user `jenkins`, uid = 1000 -# If you bind mount a volume from the host or a data container, +# If you bind mount a volume from the host or a data container, # ensure you use the same uid RUN addgroup -g ${gid} ${group} \ && adduser -h "$JENKINS_HOME" -u ${uid} -G ${group} -s /bin/bash -D ${user} -# Jenkins home directory is a volume, so configuration and build history +# Jenkins home directory is a volume, so configuration and build history # can be persisted and survive image upgrades VOLUME /var/jenkins_home -# `/usr/share/jenkins/ref/` contains all reference configuration we want -# to set on a fresh new installation. Use it to bundle additional plugins +# `/usr/share/jenkins/ref/` contains all reference configuration we want +# to set on a fresh new installation. Use it to bundle additional plugins # or config file with your custom jenkins Docker image. RUN mkdir -p /usr/share/jenkins/ref/init.groovy.d ENV TINI_VERSION 0.14.0 ENV TINI_SHA 6c41ec7d33e857d4779f14d9c74924cab0c7973485d2972419a3b7c7620ff5fd -# Use tini as subreaper in Docker container to adopt zombie processes +# Use tini as subreaper in Docker container to adopt zombie processes RUN curl -fsSL https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini-static-amd64 -o /bin/tini && chmod +x /bin/tini \ && echo "$TINI_SHA /bin/tini" | sha256sum -c - @@ -47,7 +46,7 @@ ARG JENKINS_SHA=2d71b8f87c8417f9303a73d52901a59678ee6c0eefcf7325efed6035ff39372a # Can be used to customize where jenkins.war get downloaded from ARG JENKINS_URL=https://repo.jenkins-ci.org/public/org/jenkins-ci/main/jenkins-war/${JENKINS_VERSION}/jenkins-war-${JENKINS_VERSION}.war -# could use ADD but this one does not check Last-Modified header neither does it allow to control checksum +# could use ADD but this one does not check Last-Modified header neither does it allow to control checksum # see https://github.com/docker/docker/issues/8331 RUN curl -fsSL ${JENKINS_URL} -o /usr/share/jenkins/jenkins.war \ && echo "${JENKINS_SHA} /usr/share/jenkins/jenkins.war" | sha256sum -c - From d85be653b589f78feccd4f6a7bfefb97ed5bdc94 Mon Sep 17 00:00:00 2001 From: guessi Date: Sat, 9 Dec 2017 17:33:14 +0800 Subject: [PATCH 11/11] Enhance support for write commnet in plugins.txt - add ability to write comment in plugins.txt - remove leading spaces/tabs - remove trailing spaces/tabs - protect against empty lines Enhanced #505 Signed-off-by: guessi --- install-plugins.sh | 8 ++++++- tests/install-plugins/pluginsfile/plugins.txt | 24 +++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/install-plugins.sh b/install-plugins.sh index 4478d03..34b2c23 100755 --- a/install-plugins.sh +++ b/install-plugins.sh @@ -191,7 +191,13 @@ main() { # Read plugins from stdin or from the command line arguments if [[ ($# -eq 0) ]]; then while read -r line || [ "$line" != "" ]; do - plugins+=("${line}") + # Remove leading/trailing spaces, comments, and empty lines + plugin=$(echo "${line}" | sed -e 's/^[ \t]*//g' -e 's/[ \t]*$//g' -e 's/[ \t]*#.*$//g' -e '/^[ \t]*$/d') + + # Avoid adding empty plugin into array + if [ ${#plugin} -ne 0 ]; then + plugins+=("${plugin}") + fi done else plugins=("$@") diff --git a/tests/install-plugins/pluginsfile/plugins.txt b/tests/install-plugins/pluginsfile/plugins.txt index ed6cf8d..090a044 100644 --- a/tests/install-plugins/pluginsfile/plugins.txt +++ b/tests/install-plugins/pluginsfile/plugins.txt @@ -1,5 +1,21 @@ +# comment line should be skipped + +# simple case ant:1.3 -maven-plugin:2.7.1 -mesos:0.13.0 -git:latest -filesystem_scm:experimental + +# trailing spaces +maven-plugin:2.7.1 + +# 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