move successes.groovy into canvas-builds

delete the local successes.groovy files and use the
successes library migrated to canvas-builds

refs DE-53
flag=none

test plan:
- Ensure build passes using the successes library
migrated to canvas-builds

Change-Id: I8cea11bb531012eeec2e46cd574566218fff2733
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/249202
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
QA-Review: Andrea Cirulli <andrea.cirulli@instructure.com>
QA-Review: Aaron Ogata <aogata@instructure.com>
Reviewed-by: Aaron Ogata <aogata@instructure.com>
Product-Review: Andrea Cirulli <andrea.cirulli@instructure.com>
This commit is contained in:
Andrea Cirulli 2020-10-02 16:49:51 -05:00
parent 0c25d29002
commit 33b328e305
4 changed files with 8 additions and 114 deletions

9
Jenkinsfile vendored
View File

@ -49,8 +49,12 @@ def skipIfPreviouslySuccessful(name, block) {
if (env.CANVAS_LMS_REFSPEC && !env.CANVAS_LMS_REFSPEC.contains('master')) {
name+="${env.CANVAS_LMS_REFSPEC}"
}
def successes = load('build/new-jenkins/groovy/successes.groovy')
successes.skipIfPreviouslySuccessful(name, true, block)
if (env.SKIP_CACHE.toBoolean()) {
echo "Build cache is disabled; forcing step ${name} to run, even if it was already successful."
block()
} else {
successes.skipIfPreviouslySuccessful(name, block)
}
}
def wrapBuildExecution(jobName, parameters, propagate, urlExtra) {
@ -610,7 +614,6 @@ pipeline {
}
timedStage('Mark Build as Successful') {
def successes = load 'build/new-jenkins/groovy/successes.groovy'
successes.markBuildAsSuccessful()
}
}//protectedNode

View File

@ -53,7 +53,7 @@ def appendStagesAsBuildNodes(nodes,
// mark with instance index.
// we need to do this on the main node so we dont run into
// concurrency issues with persisting the success
load('build/new-jenkins/groovy/successes.groovy').saveSuccess(test_label)
successes.saveSuccess(test_label)
})
}
}
@ -73,7 +73,6 @@ def stashBuildScripts() {
*/
def addRSpecSuites(stages) {
def rspec_node_total = load('build/new-jenkins/groovy/rspec.groovy').rspecConfig().node_total
def successes = load('build/new-jenkins/groovy/successes.groovy')
if (successes.hasSuccess('rspec', rspec_node_total)) {
echo 'not running rspec. already successful'
@ -92,7 +91,6 @@ def addRSpecSuites(stages) {
*/
def addSeleniumSuites(stages) {
def selenium_node_total = load('build/new-jenkins/groovy/rspec.groovy').seleniumConfig().node_total
def successes = load('build/new-jenkins/groovy/successes.groovy')
if (successes.hasSuccess('selenium', selenium_node_total)) {
echo 'not running selenium. already successful'

View File

@ -142,7 +142,6 @@ def uploadRSpecCoverageIfSuccessful() {
}
def _uploadCoverageIfSuccessful(prefix, total, coverage_name) {
def successes = load 'build/new-jenkins/groovy/successes.groovy'
if (successes.hasSuccess(prefix, total)) {
def reports = load 'build/new-jenkins/groovy/reports.groovy'
reports.publishSpecCoverageToS3(prefix, total, coverage_name)
@ -160,7 +159,7 @@ def uploadRSpecFailures() {
def _uploadSpecFailures(prefix, total, test_name) {
def reports = load('build/new-jenkins/groovy/reports.groovy')
def report_url = reports.publishSpecFailuresAsHTML(prefix, total, test_name)
if (!load('build/new-jenkins/groovy/successes.groovy').hasSuccessOrBuildIsSuccessful(prefix, total)) {
if (!successes.hasSuccessOrBuildIsSuccessful(prefix, total)) {
reports.appendFailMessageReport("Spec Failure For $prefix", report_url)
}
}

View File

@ -1,106 +0,0 @@
/*
* Copyright (C) 2019 - present Instructure, Inc.
*
* This file is part of Canvas.
*
* Canvas is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, version 3 of the License.
*
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
def log(message) {
echo "[successes.groovy]: ${message}"
}
def canSaveSucceses() {
return env.GERRIT_CHANGE_NUMBER && env.GERRIT_PATCHSET_NUMBER
}
def successFile() {
return "_buildmeta/${env.GERRIT_CHANGE_NUMBER}-${env.GERRIT_PATCHSET_NUMBER}-successes"
}
// we have a stage that marks a build as successful. this removes
// all success marks and replaces it with the 'build' mark. this
// causes the post hooks to be unable to read successes.
def hasSuccessOrBuildIsSuccessful(name, required_count = 1) {
return hasSuccess('build') || hasSuccess(name, required_count)
}
def hasSuccess(name, required_count = 1) {
if (!fileExists(successFile()) && canSaveSucceses()) {
copyArtifacts(
filter: '_buildmeta/*',
optional: true,
projectName: env.JOB_NAME,
parameters: "GERRIT_CHANGE_NUMBER=${env.GERRIT_CHANGE_NUMBER},GERRIT_PATCHSET_NUMBER=${env.GERRIT_PATCHSET_NUMBER}",
selector: lastCompleted()
)
archiveArtifacts(artifacts: '_buildmeta/*', allowEmptyArchive: true)
}
def result = false
if (fileExists(successFile())) {
// read the file and split for lines
def lines = readFile(successFile()).split('\n')
// count how many times the success has been marked
def count = lines.count { it == "|$name|" }
// check if the required amount of successes have happened
result = required_count <= count
}
return result
}
def clearSuccesses(name) {
if (hasSuccess(name)) {
// read all the lines from the success file
def lines = readFile(successFile()).split('\n')
// filter all of the successes we dont want
def keeping = lines.findAll { it != "|$name|" }
// save the new success file
sh "rm ${successFile()}"
sh "echo '${keeping.join('\n')}' >> ${successFile()}"
archiveArtifacts(artifacts: '_buildmeta/*')
}
}
def saveSuccess(name) {
sh 'mkdir -p _buildmeta'
sh "echo '|$name|' >> ${successFile()}"
archiveArtifacts(artifacts: '_buildmeta/*')
log "Success artifact created, future builds will skip this step $name: ${successFile()}"
sh "cat ${successFile()}"
}
// runs the body if it has not previously succeeded.
// if you don't want the success of the body to mark the
// given name as successful, pass in save = false.
def skipIfPreviouslySuccessful(name, save = true, body) {
def cacheEnabled = !configuration.getBoolean('skip-cache')
if (hasSuccess(name) && cacheEnabled) {
log "Block already successful, skipping: ${successFile()}"
} else {
if (cacheEnabled) {
log 'Build was not previously successful, executing underlying code.'
} else {
log 'Build cache is disabled! Executing all underlying code and ignoring previous build successes.'
}
body.call()
if (save) saveSuccess(name)
}
}
def markBuildAsSuccessful() {
sh "rm -f ${successFile()}"
saveSuccess('build')
}
return this