abstract failed image upload path

refs DE-338

Change-Id: I17d92a2145d8df8f3b029d435d874a50b9cb02d5
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/261113
Reviewed-by: Kyle Rosenbaum <krosenbaum@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
QA-Review: Aaron Ogata <aogata@instructure.com>
Product-Review: Aaron Ogata <aogata@instructure.com>
This commit is contained in:
Aaron Ogata 2021-03-19 08:14:58 -07:00
parent f494cafcb2
commit 142d2fbcb7
1 changed files with 22 additions and 27 deletions

49
Jenkinsfile vendored
View File

@ -283,6 +283,21 @@ def getCanvasLmsRefspec() {
}
// =========
def handleDockerBuildFailure(imagePrefix, e) {
if(configuration.isChangeMerged() || configuration.getBoolean('upload-docker-image-failures', 'false')) {
// DEBUG: In some cases, such as the the image build failing only on Jenkins, it can be useful to be able to
// download the last successful layer to debug locally. If we ever start using buildkit for the relevant
// images, then this approach will have to change as buildkit doesn't save the intermediate layers as images.
sh(script: """
docker tag \$(docker images | awk '{print \$3}' | awk 'NR==2') $imagePrefix-failed
./build/new-jenkins/docker-with-flakey-network-protection.sh push $imagePrefix-failed
""", label: 'upload failed image')
}
throw e
}
def rebaseHelper(branch, commitHistory = 100) {
git.fetch(branch, commitHistory)
if (!git.hasCommonAncestor(branch)) {
@ -496,7 +511,11 @@ pipeline {
"YARN_RUNNER_PREFIX=${env.YARN_RUNNER_PREFIX}",
]) {
slackSendCacheBuild {
sh "build/new-jenkins/docker-build.sh"
try {
sh "build/new-jenkins/docker-build.sh"
} catch(e) {
handleDockerBuildFailure("$PATCHSET_TAG-pre-merge-failed", e)
}
}
// We need to attempt to upload all prefixes here in case instructure/ruby-passenger
@ -535,18 +554,7 @@ pipeline {
try {
sh "build/new-jenkins/docker-build.sh $PATCHSET_TAG"
} catch(e) {
if(configuration.isChangeMerged() || configuration.getBoolean('upload-docker-image-failures', 'false')) {
// DEBUG: In some cases, such as the cache hash calculation missing a file, it can be useful to be able to
// download the last successful layer to debug locally. If we ever start using buildkit for the relevant
// images, then this approach will have to change as buildkit doesn't save the intermediate layers as images.
sh(script: """
docker tag \$(docker images | awk '{print \$3}' | awk 'NR==2') $PATCHSET_TAG-failed
./build/new-jenkins/docker-with-flakey-network-protection.sh push $PATCHSET_TAG-failed
""", label: 'upload failed image')
}
throw e
handleDockerBuildFailure(PATCHSET_TAG, e)
}
}
}
@ -684,20 +692,7 @@ pipeline {
} catch(e) {
jsReady = false
if(configuration.isChangeMerged() || configuration.getBoolean('upload-docker-image-failures', 'false')) {
// DEBUG: Sometimes a node can get polluted and produce an error like
// The git source https://github.com/rails-api/active_model_serializers.git is not yet checked out
// Take the last successful layer and upload it so it can be debugged. If we ever start using
// buildkit for the relevant images, then this approach will have to change as buildkit doesn't
// save the intermediate layers as images.
sh(script: """
docker tag \$(docker images | awk '{print \$3}' | awk 'NR==2') $KARMA_RUNNER_IMAGE-failed
./build/new-jenkins/docker-with-flakey-network-protection.sh push $KARMA_RUNNER_IMAGE-failed
""", label: 'upload failed image')
}
throw e
handleDockerBuildFailure(KARMA_RUNNER_IMAGE, e)
}
})
})