Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Update Jenkins build for docker publishing #1841

Merged
merged 5 commits into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -25,10 +29,6 @@ if (env.BRANCH_NAME == "master") {
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()
Expand All @@ -48,7 +48,7 @@ def abortPreviousBuilds() {
}
}

if (env.BRANCH_NAME != "master") {
if (shouldPublish()) {
abortPreviousBuilds()
}

Expand Down Expand Up @@ -163,11 +163,11 @@ try {
}
}, DockerImage: {
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() {
Expand All @@ -179,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} \
Expand All @@ -202,18 +208,34 @@ try {
sh "rm -rf ${reports_folder}"
}

if (env.BRANCH_NAME == "master") {
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()

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()
}
}
}
}
}
}
}

if (env.BRANCH_NAME == "master") {
if (shouldPublish()) {
BintrayPublish: {
def stage_name = "Bintray publish node: "
node {
Expand Down Expand Up @@ -245,7 +267,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') {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,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}"

Expand Down