From 02f6e2c43cddfb6dd00653ec00180e292dd94f85 Mon Sep 17 00:00:00 2001 From: Edward Evans Date: Fri, 9 Aug 2019 08:32:42 +1000 Subject: [PATCH 1/4] Treat release branches the same as master --- Jenkinsfile | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 07c57cd18b..c6aad78eb1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,7 +4,11 @@ import hudson.model.Result import hudson.model.Run import jenkins.model.CauseOfInterruption.UserInterruption -if (env.BRANCH_NAME == "master") { +def shouldPublish() { + return env.BRANCH_NAME == 'master' || env.BRANCH_NAME ==~ /^release-\d+\.\d+/ +} + +if (shouldPublish()) { properties([ buildDiscarder( logRotator( @@ -48,7 +52,7 @@ def abortPreviousBuilds() { } } -if (env.BRANCH_NAME != "master") { +if (shouldPublish()) { abortPreviousBuilds() } @@ -202,7 +206,7 @@ try { sh "rm -rf ${reports_folder}" } - if (env.BRANCH_NAME == "master") { + if (shouldPublish()) { stage(stage_name + 'Push image') { docker.withRegistry(registry, userAccount) { docker.image(image).push() @@ -213,7 +217,7 @@ try { } } - if (env.BRANCH_NAME == "master") { + if (shouldPublish()) { BintrayPublish: { def stage_name = "Bintray publish node: " node { @@ -245,7 +249,7 @@ try { currentBuild.result = 'FAILURE' } finally { // If we're on master and it failed, notify slack - if (env.BRANCH_NAME == "master") { + if (shouldPublish()) { def currentResult = currentBuild.result ?: 'SUCCESS' def channel = '#priv-pegasys-prod-dev' if (currentResult == 'SUCCESS') { From 4b6ff321e80a45d3600734fe684b7a872d7c5111 Mon Sep 17 00:00:00 2001 From: Edward Evans Date: Fri, 9 Aug 2019 14:26:12 +1000 Subject: [PATCH 2/4] Move docker-only variables into DockerImage block --- Jenkinsfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c6aad78eb1..c6417a2689 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -29,10 +29,6 @@ if (shouldPublish()) { def docker_image_dind = 'docker:18.06.0-ce-dind' def docker_image = 'docker:18.06.0-ce' def build_image = 'pegasyseng/pantheon-build:0.0.7-jdk11' -def registry = 'https://registry.hub.docker.com' -def userAccount = 'dockerhub-pegasysengci' -def imageRepos = 'pegasyseng' -def imageTag = 'develop' def abortPreviousBuilds() { Run previousBuild = currentBuild.rawBuild.getPreviousBuildInProgress() @@ -166,6 +162,10 @@ try { } } }, DockerImage: { + def registry = 'https://registry.hub.docker.com' + def userAccount = 'dockerhub-pegasysengci' + def imageRepos = 'pegasyseng' + def imageTag = 'develop' def stage_name = 'Docker image node: ' def image = imageRepos + '/pantheon:' + imageTag def docker_folder = 'docker' From ed0594ea6e09d985671c471e4e3fd7d740c400a1 Mon Sep 17 00:00:00 2001 From: Edward Evans Date: Tue, 13 Aug 2019 12:51:57 +1000 Subject: [PATCH 3/4] Change default docker image to pegasyseng/pantheon:$VERSION --- Jenkinsfile | 18 +++++++++++------- build.gradle | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c6417a2689..3316981771 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -162,16 +162,12 @@ try { } } }, DockerImage: { - def registry = 'https://registry.hub.docker.com' - def userAccount = 'dockerhub-pegasysengci' - def imageRepos = 'pegasyseng' - def imageTag = 'develop' def stage_name = 'Docker image node: ' - def image = imageRepos + '/pantheon:' + imageTag def docker_folder = 'docker' - def version_property_file = 'gradle.properties' def reports_folder = docker_folder + '/reports' def dockerfile = docker_folder + '/Dockerfile' + def version = '' + def image = '' node { checkout scm docker.image(build_image).inside() { @@ -183,9 +179,15 @@ try { sh './gradlew distDocker' } + stage(stage_name + 'Calculate variables') { + def gradleProperties = readProperties file: 'gradle.properties' + version = gradleProperties.version + def imageRepos = 'pegasyseng' + image = "${imageRepos}/pantheon:${version}" + } + stage(stage_name + "Test image labels") { shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() - version = sh(returnStdout: true, script: "grep -oE \"version=(.*)\" ${version_property_file} | cut -d= -f2").trim() sh "docker image inspect \ --format='{{index .Config.Labels \"org.label-schema.vcs-ref\"}}' \ ${image} \ @@ -207,6 +209,8 @@ try { } if (shouldPublish()) { + def registry = 'https://registry.hub.docker.com' + def userAccount = 'dockerhub-pegasysengci' stage(stage_name + 'Push image') { docker.withRegistry(registry, userAccount) { docker.image(image).push() diff --git a/build.gradle b/build.gradle index 1937919d08..391673fd6d 100644 --- a/build.gradle +++ b/build.gradle @@ -503,7 +503,7 @@ tasks.register("dockerDistUntar") { task distDocker(type: Exec) { dependsOn dockerDistUntar def dockerBuildVersion = project.hasProperty('release.releaseVersion') ? project.property('release.releaseVersion') : "${rootProject.version}" - def image = project.hasProperty('release.releaseVersion') ? "pegasyseng/pantheon:" + project.property('release.releaseVersion') : "pegasyseng/pantheon:develop" + def image = project.hasProperty('release.releaseVersion') ? "pegasyseng/pantheon:" + project.property('release.releaseVersion') : "pegasyseng/pantheon:${project.version}" def dockerBuildDir = "build/docker-pantheon/" workingDir "${dockerBuildDir}" From 4cdf75d909892c18cc9d90defada22abd6072764 Mon Sep 17 00:00:00 2001 From: Edward Evans Date: Tue, 13 Aug 2019 14:52:50 +1000 Subject: [PATCH 4/4] Push extra docker tags --- Jenkinsfile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 3316981771..c9f8ce200e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -214,6 +214,20 @@ try { stage(stage_name + 'Push image') { docker.withRegistry(registry, userAccount) { docker.image(image).push() + + def additionalTags = [] + if (env.BRANCH_NAME == 'master') { + additionalTags.add('develop') + } + + if (! version ==~ /.*-SNAPSHOT/) { + additionalTags.add('latest') + additionalTags.add(version.split(/\./)[0..1].join('.')) + } + + additional.each { tag -> + docker.image(image).push tag.trim() + } } } }