2021-05-11 23:38:04 +08:00
|
|
|
#!/usr/bin/env groovy
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 - 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/>.
|
|
|
|
*/
|
|
|
|
|
2021-05-19 23:45:21 +08:00
|
|
|
library 'canvas-builds-library'
|
|
|
|
loadLocalLibrary('local-lib', 'build/new-jenkins/library')
|
2021-05-11 23:38:04 +08:00
|
|
|
|
|
|
|
// if the build never starts or gets into a node block, then we
|
|
|
|
// can never load a file. and a very noisy/confusing error is thrown.
|
|
|
|
def ignoreBuildNeverStartedError(block) {
|
|
|
|
try {
|
|
|
|
block()
|
|
|
|
}
|
|
|
|
catch (org.jenkinsci.plugins.workflow.steps.MissingContextVariableException ex) {
|
|
|
|
if (!ex.message.startsWith('Required context class hudson.FilePath is missing')) {
|
|
|
|
throw ex
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
echo "ignored MissingContextVariableException: \n${ex.message}"
|
|
|
|
}
|
|
|
|
// we can ignore this very noisy error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def getMigrationsTag(name) {
|
|
|
|
(env.GERRIT_REFSPEC.contains('master')) || !migrations.cacheLoadFailed() ? migrations.imageMergeTag(name) : migrations.imagePatchsetTag(name)
|
|
|
|
}
|
|
|
|
|
|
|
|
def getPatchsetTag() {
|
|
|
|
(env.GERRIT_REFSPEC.contains('master')) ? "${configuration.buildRegistryPath()}:${env.GERRIT_BRANCH}" : imageTag.patchset()
|
|
|
|
}
|
|
|
|
|
2021-07-02 00:18:49 +08:00
|
|
|
def getResultsHTMLUrl() {
|
|
|
|
return "${env.BUILD_URL}/artifact/results.html"
|
|
|
|
}
|
|
|
|
|
2021-05-11 23:38:04 +08:00
|
|
|
pipeline {
|
|
|
|
agent { label 'canvas-docker' }
|
|
|
|
options {
|
|
|
|
ansiColor('xterm')
|
|
|
|
timestamps()
|
|
|
|
}
|
|
|
|
|
|
|
|
environment {
|
|
|
|
BUILD_REGISTRY_FQDN = configuration.buildRegistryFQDN()
|
|
|
|
POSTGRES = configuration.postgres()
|
|
|
|
RUBY = configuration.ruby() // RUBY_VERSION is a reserved keyword for ruby installs
|
|
|
|
// e.g. canvas-lms:01.123456.78-postgres-12-ruby-2.6
|
|
|
|
PATCHSET_TAG = getPatchsetTag()
|
|
|
|
|
|
|
|
CASSANDRA_PREFIX = configuration.buildRegistryPath('cassandra-migrations')
|
|
|
|
DYNAMODB_PREFIX = configuration.buildRegistryPath('dynamodb-migrations')
|
|
|
|
POSTGRES_PREFIX = configuration.buildRegistryPath('postgres-migrations')
|
|
|
|
|
|
|
|
IMAGE_CACHE_MERGE_SCOPE = configuration.gerritBranchSanitized()
|
2021-11-30 05:07:20 +08:00
|
|
|
RSPEC_PROCESSES = 6
|
2021-05-11 23:38:04 +08:00
|
|
|
|
|
|
|
CASSANDRA_IMAGE_TAG = "$CASSANDRA_PREFIX:$IMAGE_CACHE_MERGE_SCOPE-$RSPEC_PROCESSES"
|
|
|
|
DYNAMODB_IMAGE_TAG = "$DYNAMODB_PREFIX:$IMAGE_CACHE_MERGE_SCOPE-$RSPEC_PROCESSES"
|
|
|
|
POSTGRES_IMAGE_TAG = "$POSTGRES_PREFIX:$IMAGE_CACHE_MERGE_SCOPE-$RSPEC_PROCESSES"
|
|
|
|
}
|
|
|
|
|
|
|
|
stages {
|
|
|
|
stage('Setup') {
|
|
|
|
steps {
|
|
|
|
cleanAndSetup()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage('Parallel Run Tests') {
|
|
|
|
steps {
|
|
|
|
script {
|
|
|
|
def stages = [:]
|
|
|
|
|
|
|
|
distribution.stashBuildScripts()
|
|
|
|
rspecStage.createDistribution(stages)
|
|
|
|
|
|
|
|
parallel(stages)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
post {
|
|
|
|
always {
|
|
|
|
script {
|
|
|
|
ignoreBuildNeverStartedError {
|
|
|
|
node('master') {
|
|
|
|
buildSummaryReport.publishReport('Build Summary Report', currentBuild.getResult() == 'SUCCESS' ? 'SUCCESS' : 'FAILURE')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
copyArtifacts(
|
|
|
|
filter: 'tmp/rspec_results/**',
|
|
|
|
optional: false,
|
|
|
|
projectName: env.JOB_NAME,
|
|
|
|
selector: specific(env.BUILD_NUMBER),
|
|
|
|
)
|
|
|
|
|
2021-06-05 04:54:51 +08:00
|
|
|
withEnv(['COMPOSE_FILE=docker-compose.new-jenkins.yml']) {
|
|
|
|
sh """
|
|
|
|
docker-compose run -v \$(pwd)/\$LOCAL_WORKDIR/tmp/rspec_results/:/tmp/rspec_results \
|
|
|
|
--name stormbreaker-results canvas bash -c \
|
|
|
|
"bundle install; bundle exec rake stormbreaker:combine_results['/tmp/rspec_results/**']"
|
|
|
|
"""
|
|
|
|
|
|
|
|
sh 'docker cp stormbreaker-results:/usr/src/app/results.html .'
|
|
|
|
|
|
|
|
archiveArtifacts allowEmptyArchive: true, artifacts: 'results.html'
|
|
|
|
}
|
2021-06-08 09:47:29 +08:00
|
|
|
|
|
|
|
// Only alert on periodic jobs, not ones resulting from manual tests
|
|
|
|
if (env.GERRIT_EVENT_TYPE != 'comment-added') {
|
2021-07-02 00:18:49 +08:00
|
|
|
slackSend channel: '#canvas-axe-build', message: "<$env.BUILD_URL/testReport|Latest Canvas Axe Selenium Results> - <${getResultsHTMLUrl()}|HTML>"
|
2021-06-08 09:47:29 +08:00
|
|
|
}
|
2021-05-11 23:38:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
cleanup {
|
|
|
|
script {
|
|
|
|
ignoreBuildNeverStartedError {
|
|
|
|
libraryScript.execute 'bash/docker-cleanup.sh --allow-failure'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|