canvas-lms/Jenkinsfile.rspec

122 lines
4.3 KiB
Groovy

#!/usr/bin/env groovy
/*
* 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 runCoverage() {
def flags = load 'build/new-jenkins/groovy/commit-flags.groovy'
return env.RUN_COVERAGE == '1' || flags.forceRunCoverage() ? '1' : ''
}
def getImageTagVersion() {
def flags = load 'build/new-jenkins/groovy/commit-flags.groovy'
return env.RUN_COVERAGE == '1' ? 'master' : flags.getImageTagVersion()
}
pipeline {
agent { label 'canvas-docker' }
options {
ansiColor('xterm')
}
environment {
COMPOSE_FILE = 'docker-compose.new-jenkins.yml'
NAME = getImageTagVersion()
PATCHSET_TAG = "$DOCKER_REGISTRY_FQDN/jenkins/canvas-lms:$NAME"
KNAPSACK_ENABLED = 1
KNAPSACK_GENERATE_REPORT = 'false'
KNAPSACK_TEST_FILE_PATTERN = '{spec,gems/plugins/*/spec_canvas}/**/*_spec.rb'
KNAPSACK_EXCLUDE_REGEX = '/selenium/'
KNAPSACK_TEST_DIR = 'spec'
RERUNS_RETRY = 1
MAX_FAIL = 50
COVERAGE = runCoverage()
}
stages {
stage ('Distribute Rspec Tests') {
steps {
script {
stash name: "build-scripts", includes: 'build/**/*'
stash name: "build-yml", includes: 'docker-compose.*.yml'
def nodes = [:];
def ci_node_total = env.CI_NODE_TOTAL as Integer
for(int i = 0; i < ci_node_total; i++) {
def index = i;
nodes["rspec set ${(i).toString().padLeft(2, '0')}"] = {
withEnv(["TEST_ENV_NUMBER=$index", "CI_NODE_INDEX=$index"]) {
node('canvas-docker') {
stage("Running RSpec Set ${index}") {
try {
sh 'rm -rf ./tmp'
unstash name: "build-scripts"
unstash name: "build-yml"
sh 'build/new-jenkins/docker-cleanup.sh'
sh 'mkdir -p tmp'
timeout(time: 60) {
sh 'build/new-jenkins/print-env-excluding-secrets.sh'
sh 'build/new-jenkins/docker-compose-pull.sh'
sh 'build/new-jenkins/docker-compose-build-up.sh'
sh 'build/new-jenkins/docker-compose-create-migrate-database.sh'
sh 'build/new-jenkins/rspec-with-retries.sh'
}
}
catch (ex) {
// copy spec failures to local
sh 'docker cp $(docker-compose ps -q web):/usr/src/app/log/spec_failures/ ./tmp/spec_failures/'
throw ex
}
finally {
def reports = load 'build/new-jenkins/groovy/reports.groovy'
reports.stashSpecFailures(index)
if (env.COVERAGE == '1') {
sh 'docker cp $(docker-compose ps -q web):/usr/src/app/coverage/ ./tmp/spec_coverage/'
reports.stashSpecCoverage(index)
}
sh 'rm -rf ./tmp'
sh 'build/new-jenkins/docker-cleanup.sh --allow-failure'
}
}
}
}
}
}
parallel(nodes);
}
}
}
stage('Upload Coverage') {
when { expression { env.COVERAGE == '1' } }
steps {
script {
def reports = load 'build/new-jenkins/groovy/reports.groovy'
reports.publishSpecCoverageToS3(env.CI_NODE_TOTAL, "canvas-lms-rspec")
}
}
}
}
post {
failure {
script {
def reports = load 'build/new-jenkins/groovy/reports.groovy'
reports.publishSpecFailuresAsHTML(env.CI_NODE_TOTAL as Integer)
}
}
}
}