simplify logic for skipping docker build

fixes: CCI-285
flag = none

Test-Plan:
- run with skip-docker-build and ensure it works.
- run without and ensure it works

Change-Id: Ida7d623b7b20496dc9d5cfeb6c571c56eca49b7e
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/230129
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: James Butters <jbutters@instructure.com>
Reviewed-by: Derek Bender <djbender@instructure.com>
Reviewed-by: Jacob Powell <spowell@instructure.com>
QA-Review: Jacob Powell <spowell@instructure.com>
Product-Review: Jacob Powell <spowell@instructure.com>
This commit is contained in:
Rex Fleischer 2020-03-16 10:10:43 -07:00
parent 664090f1df
commit dfd1cf11e3
2 changed files with 17 additions and 22 deletions

37
Jenkinsfile vendored
View File

@ -38,16 +38,6 @@ def getImageTagVersion() {
flags.getImageTagVersion()
}
def runBuildImageMaybe(block) {
def flags = load('build/new-jenkins/groovy/commit-flags.groovy')
if (flags.hasFlag('skip-docker-build')) {
echo "Skip building image requested"
} else {
def successes = load('build/new-jenkins/groovy/successes.groovy')
successes.skipIfPreviouslySuccessful("build-and-push-image", true, block)
}
}
def skipIfPreviouslySuccessful(name, block) {
def successes = load('build/new-jenkins/groovy/successes.groovy')
successes.skipIfPreviouslySuccessful(name, true, block)
@ -206,21 +196,26 @@ pipeline {
stage ('Build Docker Image') {
steps {
timeout(time: 36) { /* this timeout is `2 * average build time` which currently: 18m * 2 = 36m */
runBuildImageMaybe() {
skipIfPreviouslySuccessful('docker-build-and-push') {
script {
def flags = load('build/new-jenkins/groovy/commit-flags.groovy')
if (!flags.hasFlag('skip-cache')) {
// canvas-lms:$GERRIT_BRANCH as the image cache for this build (i.e. canvas-lms:master)
sh 'docker pull $MERGE_TAG || true'
if (flags.hasFlag('skip-docker-build')) {
sh 'docker pull $MERGE_TAG'
sh 'docker tag $MERGE_TAG $PATCHSET_TAG'
}
else {
if (!flags.hasFlag('skip-cache')) {
sh 'docker pull $MERGE_TAG || true'
}
sh """
docker build \
--tag $PATCHSET_TAG \
--build-arg RUBY_PASSENGER=$RUBY_PASSENGER \
--build-arg POSTGRES_VERSION=$POSTGRES \
.
"""
}
}
sh """
docker build \
--tag $PATCHSET_TAG \
--build-arg RUBY_PASSENGER=$RUBY_PASSENGER \
--build-arg POSTGRES_VERSION=$POSTGRES \
.
"""
sh "docker push $PATCHSET_TAG"
}
}

View File

@ -39,7 +39,7 @@ def hasFlag(name) {
def getImageTagVersion() {
// 'refs/changes/63/181863/8' -> '63.181863.8'
return hasFlag('skip-docker-build') ? 'master' : "${env.GERRIT_REFSPEC}".minus('refs/changes/').replaceAll('/','.')
return "${env.GERRIT_REFSPEC}".minus('refs/changes/').replaceAll('/','.')
}
def forceRunCoverage() {