From dfd1cf11e30c48bff84f4c81458a876bc75ba824 Mon Sep 17 00:00:00 2001 From: Rex Fleischer Date: Mon, 16 Mar 2020 10:10:43 -0700 Subject: [PATCH] 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 Reviewed-by: James Butters Reviewed-by: Derek Bender Reviewed-by: Jacob Powell QA-Review: Jacob Powell Product-Review: Jacob Powell --- Jenkinsfile | 37 +++++++++----------- build/new-jenkins/groovy/commit-flags.groovy | 2 +- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 109b39d538a..c6ec791bb3c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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" } } diff --git a/build/new-jenkins/groovy/commit-flags.groovy b/build/new-jenkins/groovy/commit-flags.groovy index 061591bc93d..e8c63e7412e 100644 --- a/build/new-jenkins/groovy/commit-flags.groovy +++ b/build/new-jenkins/groovy/commit-flags.groovy @@ -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() {