diff --git a/Dockerfile-alpine b/Dockerfile-alpine index 5ed0c21..81bb6f6 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 tini @@ -14,17 +13,17 @@ 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 @@ -40,7 +39,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 - diff --git a/Jenkinsfile b/Jenkinsfile index f42d95e..f2620fc 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 H/6 * * *')]), ]) node('docker') { 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 diff --git a/install-plugins.sh b/install-plugins.sh index 10031b4..34b2c23 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" & @@ -190,8 +190,14 @@ main() { # Read plugins from stdin or from the command line arguments if [[ ($# -eq 0) ]]; then - while read -r line; do - plugins+=("${line}") + while read -r line || [ "$line" != "" ]; do + # 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=("$@") @@ -206,6 +212,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 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" \ diff --git a/tests/install-plugins.bats b/tests/install-plugins.bats index 3cf7093..9982c57 100644 --- a/tests/install-plugins.bats +++ b/tests/install-plugins.bats @@ -26,7 +26,7 @@ SUT_IMAGE=$(sut_image) @test "plugins are installed with install-plugins.sh" { run docker_build_child $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 @@ SUT_IMAGE=$(sut_image) @test "plugins are installed with install-plugins.sh from a plugins file" { run docker_build_child $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 @@ -84,8 +84,8 @@ SUT_IMAGE=$(sut_image) @test "plugins are installed with install-plugins.sh even when already exist" { 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 javadoc' 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 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