2019-02-16 04:16:49 +08:00
#!/usr/bin/env groovy
2019-03-13 23:54:18 +08:00
/*
* 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/>.
*/
2021-05-03 21:52:46 +08:00
def FILES_CHANGED_STAGE = 'Detect Files Changed'
def JS_BUILD_IMAGE_STAGE = 'Javascript (Build Image)'
2021-05-11 04:31:33 +08:00
def LINTERS_BUILD_IMAGE_STAGE = 'Linters (Build Image)'
2021-05-03 21:52:46 +08:00
def RUN_MIGRATIONS_STAGE = 'Run Migrations'
2021-03-04 03:35:07 +08:00
2020-02-15 06:02:23 +08:00
def buildParameters = [
2019-08-15 02:43:09 +08:00
string(name: 'GERRIT_REFSPEC', value: "${env.GERRIT_REFSPEC}"),
string(name: 'GERRIT_EVENT_TYPE', value: "${env.GERRIT_EVENT_TYPE}"),
2020-01-18 04:26:48 +08:00
string(name: 'GERRIT_PROJECT', value: "${env.GERRIT_PROJECT}"),
2019-08-15 02:43:09 +08:00
string(name: 'GERRIT_BRANCH', value: "${env.GERRIT_BRANCH}"),
string(name: 'GERRIT_CHANGE_NUMBER', value: "${env.GERRIT_CHANGE_NUMBER}"),
string(name: 'GERRIT_PATCHSET_NUMBER', value: "${env.GERRIT_PATCHSET_NUMBER}"),
string(name: 'GERRIT_EVENT_ACCOUNT_NAME', value: "${env.GERRIT_EVENT_ACCOUNT_NAME}"),
2019-11-16 02:12:18 +08:00
string(name: 'GERRIT_EVENT_ACCOUNT_EMAIL', value: "${env.GERRIT_EVENT_ACCOUNT_EMAIL}"),
string(name: 'GERRIT_CHANGE_COMMIT_MESSAGE', value: "${env.GERRIT_CHANGE_COMMIT_MESSAGE}"),
string(name: 'GERRIT_HOST', value: "${env.GERRIT_HOST}"),
2019-12-20 02:55:08 +08:00
string(name: 'GERGICH_PUBLISH', value: "${env.GERGICH_PUBLISH}"),
string(name: 'MASTER_BOUNCER_RUN', value: "${env.MASTER_BOUNCER_RUN}")
2019-08-15 02:43:09 +08:00
]
2020-11-24 01:55:14 +08:00
def dockerDevFiles = [
'^docker-compose/',
2021-03-20 03:18:53 +08:00
'^script/common/',
2020-11-24 01:55:14 +08:00
'^script/canvas_update',
'^docker-compose.yml',
'^Dockerfile$',
'^lib/tasks/',
'Jenkinsfile.docker-smoke'
]
2021-03-16 22:52:49 +08:00
def getSummaryUrl() {
return "${env.BUILD_URL}/build-summary-report"
}
2020-08-28 20:08:22 +08:00
def getDockerWorkDir() {
2021-05-03 21:52:46 +08:00
return env.GERRIT_PROJECT == 'canvas-lms' ? '/usr/src/app' : "/usr/src/app/gems/plugins/${env.GERRIT_PROJECT}"
2020-08-28 20:08:22 +08:00
}
def getLocalWorkDir() {
2021-05-03 21:52:46 +08:00
return env.GERRIT_PROJECT == 'canvas-lms' ? '.' : "gems/plugins/${env.GERRIT_PROJECT}"
2020-08-28 20:08:22 +08:00
}
2020-03-16 20:23:58 +08:00
// return false if the current patchset tag doesn't match the
2020-08-12 01:14:14 +08:00
// mainline publishable tag. i.e. ignore pg-9.5 builds
2020-02-15 06:02:23 +08:00
def isPatchsetPublishable() {
env.PATCHSET_TAG == env.PUBLISHABLE_TAG
2019-11-23 04:57:11 +08:00
}
2020-09-02 22:46:17 +08:00
def isPatchsetRetriggered() {
2021-05-03 21:52:46 +08:00
if (env.IS_AUTOMATIC_RETRIGGER == '1') {
2020-09-03 22:31:09 +08:00
return true
}
2020-09-02 22:46:17 +08:00
def userCause = currentBuild.getBuildCauses('com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritUserCause')
return userCause && userCause[0].shortDescription.contains('Retriggered')
}
2020-07-29 03:14:53 +08:00
def postFn(status) {
2020-11-03 09:34:07 +08:00
try {
def requestStartTime = System.currentTimeMillis()
node('master') {
def requestEndTime = System.currentTimeMillis()
reportToSplunk('node_request_time', [
'nodeName': 'master',
'nodeLabel': 'master',
'requestTime': requestEndTime - requestStartTime,
])
2021-03-04 03:35:07 +08:00
buildSummaryReport.publishReport('Build Summary Report', status)
2020-11-03 09:34:07 +08:00
2021-05-03 21:52:46 +08:00
if (isPatchsetPublishable()) {
2021-04-09 00:42:35 +08:00
dockerUtils.tagRemote(env.PATCHSET_TAG, env.EXTERNAL_TAG)
}
2021-05-03 21:52:46 +08:00
if (status == 'SUCCESS' && configuration.isChangeMerged() && isPatchsetPublishable()) {
2020-12-03 04:36:48 +08:00
dockerUtils.tagRemote(env.PATCHSET_TAG, env.MERGE_TAG)
2021-04-13 03:27:47 +08:00
dockerUtils.tagRemote(env.CASSANDRA_IMAGE_TAG, env.CASSANDRA_MERGE_IMAGE)
dockerUtils.tagRemote(env.DYNAMODB_IMAGE_TAG, env.DYNAMODB_MERGE_IMAGE)
dockerUtils.tagRemote(env.POSTGRES_IMAGE_TAG, env.POSTGRES_MERGE_IMAGE)
2020-11-03 09:34:07 +08:00
}
}
} finally {
2021-05-03 21:52:46 +08:00
if (status == 'SUCCESS') {
2021-04-28 06:29:29 +08:00
maybeSlackSendSuccess()
} else {
2020-11-03 09:34:07 +08:00
maybeSlackSendFailure()
maybeRetrigger()
}
2020-09-02 22:46:17 +08:00
}
}
2020-09-03 22:31:09 +08:00
def shouldPatchsetRetrigger() {
// NOTE: The IS_AUTOMATIC_RETRIGGER check is here to ensure that the parameter is properly defined for the triggering job.
// If it isn't, we have the risk of triggering this job over and over in an infinite loop.
return env.IS_AUTOMATIC_RETRIGGER == '0' && (
env.GERRIT_EVENT_TYPE == 'change-merged' ||
configuration.getBoolean('change-merged') && configuration.getBoolean('enable-automatic-retrigger', '0')
)
}
def maybeRetrigger() {
2021-05-03 21:52:46 +08:00
if (shouldPatchsetRetrigger() && !isPatchsetRetriggered()) {
2020-09-03 22:31:09 +08:00
def retriggerParams = currentBuild.rawBuild.getAction(ParametersAction).getParameters()
retriggerParams = retriggerParams.findAll { record ->
record.name != 'IS_AUTOMATIC_RETRIGGER'
}
2021-05-03 21:52:46 +08:00
retriggerParams << new StringParameterValue('IS_AUTOMATIC_RETRIGGER', '1')
2020-09-03 22:31:09 +08:00
build(job: env.JOB_NAME, parameters: retriggerParams, propagate: false, wait: false)
}
}
2020-09-02 22:46:17 +08:00
def maybeSlackSendFailure() {
2021-05-03 21:52:46 +08:00
if (configuration.isChangeMerged()) {
2020-07-29 03:14:53 +08:00
def branchSegment = env.GERRIT_BRANCH ? "[$env.GERRIT_BRANCH]" : ''
def authorSlackId = env.GERRIT_EVENT_ACCOUNT_EMAIL ? slackUserIdFromEmail(email: env.GERRIT_EVENT_ACCOUNT_EMAIL, botUser: true, tokenCredentialId: 'slack-user-id-lookup') : ''
def authorSlackMsg = authorSlackId ? "<@$authorSlackId>" : env.GERRIT_EVENT_ACCOUNT_NAME
2020-09-09 02:22:51 +08:00
def authorSegment = "Patchset <${env.GERRIT_CHANGE_URL}|#${env.GERRIT_CHANGE_NUMBER}> by ${authorSlackMsg} failed against ${branchSegment}"
2020-09-18 04:59:28 +08:00
def extra = "Please investigate the cause of the failure, and respond to this message with your diagnosis. If you need help, don't hesitate to tag @ oncall and our on call will assist in looking at the build. Further details of our post-merge failure process can be found at this <${configuration.getFailureWiki()}|link>. Thanks!"
2020-09-09 02:22:51 +08:00
2020-07-29 03:14:53 +08:00
slackSend(
2020-09-02 05:02:38 +08:00
channel: getSlackChannel(),
2020-07-29 03:14:53 +08:00
color: 'danger',
2021-03-16 22:52:49 +08:00
message: "${authorSegment}. Build <${getSummaryUrl()}|#${env.BUILD_NUMBER}>\n\n$extra"
2020-09-02 01:18:16 +08:00
)
}
2021-04-13 05:26:12 +08:00
slackSend(
channel: '#canvas_builds-noisy',
color: 'danger',
message: "${env.JOB_NAME} <${getSummaryUrl()}|#${env.BUILD_NUMBER}> failed. Patchset <${env.GERRIT_CHANGE_URL}|#${env.GERRIT_CHANGE_NUMBER}>."
)
2020-09-02 01:18:16 +08:00
}
2020-09-02 22:46:17 +08:00
def maybeSlackSendSuccess() {
2021-05-03 21:52:46 +08:00
if (configuration.isChangeMerged() && isPatchsetRetriggered()) {
2020-09-02 22:46:17 +08:00
slackSend(
channel: getSlackChannel(),
color: 'good',
2021-03-16 22:52:49 +08:00
message: "Patchset <${env.GERRIT_CHANGE_URL}|#${env.GERRIT_CHANGE_NUMBER}> succeeded on re-trigger. Build <${getSummaryUrl()}|#${env.BUILD_NUMBER}>"
2020-09-02 22:46:17 +08:00
)
}
2021-04-13 05:26:12 +08:00
slackSend(
channel: '#canvas_builds-noisy',
color: 'good',
message: "${env.JOB_NAME} <${getSummaryUrl()}|#${env.BUILD_NUMBER}> succeeded. Patchset <${env.GERRIT_CHANGE_URL}|#${env.GERRIT_CHANGE_NUMBER}>."
)
2020-09-02 22:46:17 +08:00
}
2020-09-02 01:18:16 +08:00
2020-09-02 22:46:17 +08:00
def maybeSlackSendRetrigger() {
2021-05-03 21:52:46 +08:00
if (configuration.isChangeMerged() && isPatchsetRetriggered()) {
2020-09-02 01:18:16 +08:00
slackSend(
channel: getSlackChannel(),
color: 'warning',
2020-09-03 22:16:39 +08:00
message: "Patchset <${env.GERRIT_CHANGE_URL}|#${env.GERRIT_CHANGE_NUMBER}> by ${env.GERRIT_EVENT_ACCOUNT_EMAIL} has been re-triggered. Build <${env.BUILD_URL}|#${env.BUILD_NUMBER}>"
2020-07-29 03:14:53 +08:00
)
}
}
2020-08-05 05:42:10 +08:00
// These functions are intentionally pinned to GERRIT_EVENT_TYPE == 'change-merged' to ensure that real post-merge
// builds always run correctly. We intentionally ignore overrides for version pins, docker image paths, etc when
// running real post-merge builds.
// =========
2020-08-01 00:30:29 +08:00
2020-09-02 05:02:38 +08:00
def getSlackChannel() {
return env.GERRIT_EVENT_TYPE == 'change-merged' ? '#canvas_builds' : '#devx-bots'
2020-08-05 05:42:10 +08:00
}
2020-09-02 05:02:38 +08:00
2020-11-02 23:39:02 +08:00
@groovy.transform.Field def CANVAS_BUILDS_REFSPEC_REGEX = /\[canvas\-builds\-refspec=(.+?)\]/
def getCanvasBuildsRefspec() {
def commitMessage = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : null
2021-05-03 21:52:46 +08:00
if (env.GERRIT_EVENT_TYPE == 'change-merged' || !commitMessage || !(commitMessage =~ CANVAS_BUILDS_REFSPEC_REGEX).find()) {
2021-01-06 00:03:51 +08:00
return env.GERRIT_BRANCH.contains('stable/') ? env.GERRIT_BRANCH : 'master'
2020-11-02 23:39:02 +08:00
}
return (commitMessage =~ CANVAS_BUILDS_REFSPEC_REGEX).findAll()[0][1]
}
2020-11-10 00:03:25 +08:00
@groovy.transform.Field def CANVAS_LMS_REFSPEC_REGEX = /\[canvas\-lms\-refspec=(.+?)\]/
2020-10-08 22:19:24 +08:00
def getCanvasLmsRefspec() {
2020-11-10 00:03:25 +08:00
// If stable branch, first search commit message for canvas-lms-refspec. If not present use stable branch head on origin.
2021-05-03 21:52:46 +08:00
if (env.GERRIT_BRANCH.contains('stable/')) {
2020-11-10 00:03:25 +08:00
def commitMessage = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : null
2021-05-03 21:52:46 +08:00
if ((commitMessage =~ CANVAS_LMS_REFSPEC_REGEX).find()) {
2020-11-10 00:03:25 +08:00
return configuration.canvasLmsRefspec()
}
return "+refs/heads/$GERRIT_BRANCH:refs/remotes/origin/$GERRIT_BRANCH"
}
2020-10-08 22:19:24 +08:00
return env.GERRIT_EVENT_TYPE == 'change-merged' ? configuration.canvasLmsRefspecDefault() : configuration.canvasLmsRefspec()
}
2020-08-05 05:42:10 +08:00
// =========
2020-11-02 23:39:02 +08:00
library "canvas-builds-library@${getCanvasBuildsRefspec()}"
2021-05-03 21:52:46 +08:00
loadLocalLibrary('local-lib', 'build/new-jenkins/library')
2020-11-02 23:39:02 +08:00
2020-12-09 06:57:08 +08:00
configuration.setUseCommitMessageFlags(env.GERRIT_EVENT_TYPE != 'change-merged')
2021-04-24 02:36:52 +08:00
protectedNode.setReportUnhandledExceptions(!env.JOB_NAME.endsWith('Jenkinsfile'))
2020-12-09 06:57:08 +08:00
2019-02-16 04:16:49 +08:00
pipeline {
2020-07-27 00:18:52 +08:00
agent none
2020-05-09 02:23:07 +08:00
options {
ansiColor('xterm')
2021-01-07 01:11:17 +08:00
timeout(time: 1, unit: 'HOURS')
2020-05-09 02:23:07 +08:00
timestamps()
}
2019-02-20 23:41:00 +08:00
2019-02-21 01:06:06 +08:00
environment {
2019-03-12 09:55:34 +08:00
GERRIT_PORT = '29418'
2019-02-21 01:22:05 +08:00
GERRIT_URL = "$GERRIT_HOST:$GERRIT_PORT"
2020-06-17 02:23:25 +08:00
BUILD_REGISTRY_FQDN = configuration.buildRegistryFQDN()
2020-12-09 06:57:08 +08:00
BUILD_IMAGE = configuration.buildRegistryPath()
2020-06-17 02:23:25 +08:00
POSTGRES = configuration.postgres()
2020-03-16 20:23:58 +08:00
POSTGRES_CLIENT = configuration.postgresClient()
2020-07-31 00:27:16 +08:00
SKIP_CACHE = configuration.skipCache()
2019-02-16 04:16:49 +08:00
2020-08-12 01:14:14 +08:00
// e.g. postgres-12-ruby-2.6
2020-07-22 10:06:57 +08:00
TAG_SUFFIX = imageTag.suffix()
2019-02-21 01:22:05 +08:00
2020-03-16 20:23:58 +08:00
// e.g. canvas-lms:01.123456.78-postgres-12-ruby-2.6
2020-12-09 06:57:08 +08:00
PATCHSET_TAG = imageTag.patchset()
2020-02-15 06:02:23 +08:00
2020-08-12 01:14:14 +08:00
// e.g. canvas-lms:01.123456.78-postgres-12-ruby-2.6
2020-12-09 06:57:08 +08:00
PUBLISHABLE_TAG = imageTag.publishableTag()
2020-02-15 06:02:23 +08:00
// e.g. canvas-lms:master when not on another branch
2020-12-09 06:57:08 +08:00
MERGE_TAG = imageTag.mergeTag()
2020-04-04 04:05:52 +08:00
// e.g. canvas-lms:01.123456.78; this is for consumers like Portal 2 who want to build a patchset
2020-12-09 06:57:08 +08:00
EXTERNAL_TAG = imageTag.externalTag()
2020-03-16 20:23:58 +08:00
ALPINE_MIRROR = configuration.alpineMirror()
NODE = configuration.node()
RUBY = configuration.ruby() // RUBY_VERSION is a reserved keyword for ruby installs
2021-01-20 03:15:52 +08:00
RSPEC_PROCESSES = 4
2020-06-27 03:37:32 +08:00
2021-01-12 08:54:32 +08:00
CASSANDRA_PREFIX = configuration.buildRegistryPath('cassandra-migrations')
DYNAMODB_PREFIX = configuration.buildRegistryPath('dynamodb-migrations')
2021-05-03 21:52:46 +08:00
KARMA_BUILDER_PREFIX = configuration.buildRegistryPath('karma-builder')
KARMA_RUNNER_PREFIX = configuration.buildRegistryPath('karma-runner')
2021-05-11 02:59:51 +08:00
LINTERS_RUNNER_PREFIX = configuration.buildRegistryPath('linters-runner')
2021-01-12 08:54:32 +08:00
POSTGRES_PREFIX = configuration.buildRegistryPath('postgres-migrations')
2021-05-03 21:52:46 +08:00
RUBY_RUNNER_PREFIX = configuration.buildRegistryPath('ruby-runner')
YARN_RUNNER_PREFIX = configuration.buildRegistryPath('yarn-runner')
WEBPACK_BUILDER_PREFIX = configuration.buildRegistryPath('webpack-builder')
WEBPACK_CACHE_PREFIX = configuration.buildRegistryPath('webpack-cache')
2020-08-10 03:30:45 +08:00
2020-12-09 04:02:29 +08:00
IMAGE_CACHE_BUILD_SCOPE = configuration.gerritChangeNumber()
IMAGE_CACHE_MERGE_SCOPE = configuration.gerritBranchSanitized()
2021-01-12 08:54:32 +08:00
IMAGE_CACHE_UNIQUE_SCOPE = "${imageTagVersion()}-$TAG_SUFFIX"
2021-04-13 03:27:47 +08:00
CASSANDRA_IMAGE_TAG = "$CASSANDRA_PREFIX:$IMAGE_CACHE_UNIQUE_SCOPE"
DYNAMODB_IMAGE_TAG = "$DYNAMODB_PREFIX:$IMAGE_CACHE_UNIQUE_SCOPE"
POSTGRES_IMAGE_TAG = "$POSTGRES_PREFIX:$IMAGE_CACHE_UNIQUE_SCOPE"
2021-01-12 08:54:32 +08:00
WEBPACK_BUILDER_IMAGE = "$WEBPACK_BUILDER_PREFIX:$IMAGE_CACHE_UNIQUE_SCOPE"
2020-12-03 01:02:24 +08:00
2021-01-20 03:15:52 +08:00
CASSANDRA_MERGE_IMAGE = "$CASSANDRA_PREFIX:$IMAGE_CACHE_MERGE_SCOPE-$RSPEC_PROCESSES"
DYNAMODB_MERGE_IMAGE = "$DYNAMODB_PREFIX:$IMAGE_CACHE_MERGE_SCOPE-$RSPEC_PROCESSES"
2021-02-02 01:47:21 +08:00
KARMA_RUNNER_IMAGE = "$KARMA_RUNNER_PREFIX:$IMAGE_CACHE_UNIQUE_SCOPE"
2021-05-11 02:59:51 +08:00
LINTERS_RUNNER_IMAGE = "$LINTERS_RUNNER_PREFIX:$IMAGE_CACHE_UNIQUE_SCOPE"
2021-01-20 03:15:52 +08:00
POSTGRES_MERGE_IMAGE = "$POSTGRES_PREFIX:$IMAGE_CACHE_MERGE_SCOPE-$RSPEC_PROCESSES"
2020-08-15 00:13:24 +08:00
// This is primarily for the plugin build
// for testing canvas-lms changes against plugin repo changes
2020-11-02 23:39:02 +08:00
CANVAS_BUILDS_REFSPEC = getCanvasBuildsRefspec()
2020-10-08 22:19:24 +08:00
CANVAS_LMS_REFSPEC = getCanvasLmsRefspec()
2020-08-28 20:08:22 +08:00
DOCKER_WORKDIR = getDockerWorkDir()
LOCAL_WORKDIR = getLocalWorkDir()
2020-02-15 06:02:23 +08:00
}
2019-12-10 02:37:05 +08:00
2020-02-15 06:02:23 +08:00
stages {
2020-07-27 00:18:52 +08:00
stage('Environment') {
2019-03-12 09:55:34 +08:00
steps {
2020-07-27 00:18:52 +08:00
script {
2021-03-17 02:38:05 +08:00
node('master') {
if (configuration.skipCi()) {
2021-01-06 01:24:43 +08:00
currentBuild.result = 'NOT_BUILT'
2021-05-03 21:52:46 +08:00
gerrit.submitLintReview('-2', 'Build not executed due to [skip-ci] flag')
error '[skip-ci] flag enabled: skipping the build'
2021-01-06 01:24:43 +08:00
return
2021-05-03 21:52:46 +08:00
} else if (extendedStage.isAllowStagesFilterUsed() || extendedStage.isIgnoreStageResultsFilterUsed() || extendedStage.isSkipStagesFilterUsed()) {
gerrit.submitLintReview('-2', 'One or more build flags causes a subset of the build to be run')
2021-03-17 02:38:05 +08:00
} else {
2021-05-03 21:52:46 +08:00
gerrit.submitLintReview('0')
2021-03-11 04:12:29 +08:00
}
2021-01-06 01:24:43 +08:00
}
2021-03-11 04:12:29 +08:00
2020-08-05 05:42:10 +08:00
// Ensure that all build flags are compatible.
2021-05-03 21:52:46 +08:00
if (configuration.getBoolean('change-merged') && configuration.isValueDefault('build-registry-path')) {
error 'Manually triggering the change-merged build path must be combined with a custom build-registry-path'
2020-08-05 05:42:10 +08:00
return
}
2021-05-10 21:59:33 +08:00
reportToSplunk('is_kubernetes', [
'value': configuration.isKubernetesEnabled(),
])
2020-09-02 22:46:17 +08:00
maybeSlackSendRetrigger()
2020-09-02 01:18:16 +08:00
2021-04-15 22:42:07 +08:00
def buildSummaryReportHooks = [
onStageEnded: { stageName, _, buildResult ->
2021-05-03 21:52:46 +08:00
if (buildResult) {
2021-04-21 06:29:56 +08:00
buildSummaryReport.addFailureRun(stageName, buildResult)
buildSummaryReport.addRunTestActions(stageName, buildResult)
buildSummaryReport.setStageIgnored(stageName)
}
2021-04-15 22:42:07 +08:00
}
]
2021-04-14 03:45:41 +08:00
def postBuildHandler = [
2021-04-15 06:53:28 +08:00
onStageEnded: { _, stageConfig ->
2021-04-15 22:42:07 +08:00
buildSummaryReport.addFailureRun('Main Build', currentBuild)
2021-04-13 09:12:09 +08:00
postFn(stageConfig.status())
}
2021-04-14 03:45:41 +08:00
]
2021-04-09 04:15:30 +08:00
2021-04-15 06:16:39 +08:00
extendedStage('Root').hooks(postBuildHandler).obeysAllowStages(false).timings(false).execute {
2021-04-13 09:12:09 +08:00
def rootStages = [:]
2021-04-09 07:37:18 +08:00
2021-04-13 09:12:09 +08:00
buildParameters += string(name: 'CANVAS_BUILDS_REFSPEC', value: "${env.CANVAS_BUILDS_REFSPEC}")
buildParameters += string(name: 'PATCHSET_TAG', value: "${env.PATCHSET_TAG}")
buildParameters += string(name: 'POSTGRES', value: "${env.POSTGRES}")
buildParameters += string(name: 'RUBY', value: "${env.RUBY}")
2021-05-03 21:52:46 +08:00
buildParameters += string(name: 'CANVAS_RAILS6_0', value: '1')
2021-04-09 07:37:18 +08:00
2021-04-13 09:12:09 +08:00
// If modifying any of our Jenkinsfiles set JENKINSFILE_REFSPEC for sub-builds to use Jenkinsfiles in
2021-04-16 04:54:42 +08:00
// the gerrit rather than master. Stable branches also need to check out the JENKINSFILE_REFSPEC to prevent
// the job default from pulling master.
2021-05-03 21:52:46 +08:00
if (env.GERRIT_PROJECT == 'canvas-lms' && env.JOB_NAME.endsWith('Jenkinsfile')) {
2021-04-16 04:54:42 +08:00
buildParameters += string(name: 'JENKINSFILE_REFSPEC', value: "${env.GERRIT_REFSPEC}")
2021-05-03 21:52:46 +08:00
} else if (env.GERRIT_PROJECT == 'canvas-lms' && env.JOB_NAME.endsWith('stable')) {
2021-04-16 04:54:42 +08:00
buildParameters += string(name: 'JENKINSFILE_REFSPEC', value: "${env.GERRIT_REFSPEC}")
2021-04-13 09:12:09 +08:00
}
2021-03-23 05:36:59 +08:00
2021-05-03 21:52:46 +08:00
if (env.GERRIT_PROJECT != 'canvas-lms') {
2021-04-13 09:12:09 +08:00
// the plugin builds require the canvas lms refspec to be different. so only
// set this refspec if the main build is requesting it to be set.
// NOTE: this is only being set in main-from-plugin build. so main-canvas wont run this.
buildParameters += string(name: 'CANVAS_LMS_REFSPEC', value: env.CANVAS_LMS_REFSPEC)
}
2021-04-12 23:31:38 +08:00
2021-04-21 01:15:44 +08:00
extendedStage('Builder').nodeRequirements(label: 'canvas-docker', podTemplate: libraryResource('/pod_templates/docker_base.yml'), container: 'docker').obeysAllowStages(false).timings(false).queue(rootStages) {
2021-04-13 09:12:09 +08:00
// Use a nospot instance for now to avoid really bad UX. Jenkins currently will
// wait for the current steps to complete (even wait to spin up a node), causing
// extremely long wait times for a restart. Investigation in DE-166 / DE-158.
2021-04-14 22:13:42 +08:00
extendedStage('Setup')
.obeysAllowStages(false)
.timeout(2)
.execute({ setupStage() })
2021-04-12 23:31:38 +08:00
2021-04-14 22:13:42 +08:00
extendedStage(FILES_CHANGED_STAGE)
.obeysAllowStages(false)
.timeout(2)
.execute { stageConfig ->
stageConfig.value('dockerDevFiles', git.changedFiles(dockerDevFiles, 'HEAD^'))
stageConfig.value('migrationFiles', sh(script: 'build/new-jenkins/check-for-migrations.sh', returnStatus: true) == 0)
2020-07-27 00:18:52 +08:00
2021-04-14 22:13:42 +08:00
dir(env.LOCAL_WORKDIR) {
stageConfig.value('specFiles', sh(script: '${WORKSPACE}/build/new-jenkins/spec-changes.sh', returnStatus: true) == 0)
}
2021-04-12 23:31:38 +08:00
2021-04-14 22:13:42 +08:00
// Remove the @tmp directory created by dir() for plugin builds, so bundler doesn't get confused.
// https://issues.jenkins.io/browse/JENKINS-52750
2021-05-03 21:52:46 +08:00
if (env.GERRIT_PROJECT != 'canvas-lms') {
2021-04-14 22:13:42 +08:00
sh "rm -vrf $LOCAL_WORKDIR@tmp"
}
2021-04-12 23:31:38 +08:00
2021-04-14 22:13:42 +08:00
distribution.stashBuildScripts()
}
2021-04-12 23:31:38 +08:00
2021-04-14 22:13:42 +08:00
extendedStage('Rebase')
.obeysAllowStages(false)
.required(!configuration.isChangeMerged() && env.GERRIT_PROJECT == 'canvas-lms')
.timeout(2)
.execute({ rebaseStage() })
2021-04-12 23:31:38 +08:00
2021-04-14 22:13:42 +08:00
extendedStage('Build Docker Image (Pre-Merge)')
.obeysAllowStages(false)
.required(configuration.isChangeMerged())
.timeout(20)
.execute(buildDockerImageStage.&premergeCacheImage)
2021-04-09 23:24:53 +08:00
2021-04-14 22:13:42 +08:00
extendedStage('Build Docker Image')
.obeysAllowStages(false)
.timeout(20)
.execute(buildDockerImageStage.&patchsetImage)
2021-04-12 23:31:38 +08:00
2021-04-14 22:13:42 +08:00
extendedStage(RUN_MIGRATIONS_STAGE)
.obeysAllowStages(false)
.timeout(10)
.execute({ runMigrationsStage() })
2021-04-12 23:31:38 +08:00
2021-04-14 22:13:42 +08:00
extendedStage('Parallel Run Tests').obeysAllowStages(false).execute { _, buildConfig ->
def stages = [:]
2021-04-12 23:31:38 +08:00
2021-04-15 22:42:07 +08:00
extendedStage('Consumer Smoke Test').queue(stages) {
2021-04-14 22:13:42 +08:00
sh 'build/new-jenkins/consumer-smoke-test.sh'
2021-04-13 09:12:09 +08:00
}
2021-04-14 22:13:42 +08:00
extendedStage(JS_BUILD_IMAGE_STAGE)
.queue(stages, buildDockerImageStage.&jsImage)
2021-05-11 04:31:33 +08:00
extendedStage(LINTERS_BUILD_IMAGE_STAGE)
.queue(stages, buildDockerImageStage.&lintersImage)
2021-04-14 22:13:42 +08:00
parallel(stages)
2021-04-12 23:31:38 +08:00
}
2021-04-13 09:12:09 +08:00
}
extendedStage("${FILES_CHANGED_STAGE} (Waiting for Dependencies)").obeysAllowStages(false).waitsFor(FILES_CHANGED_STAGE, 'Builder').queue(rootStages) { _, buildConfig ->
def nestedStages = [:]
2021-04-09 23:24:53 +08:00
2021-04-13 09:12:09 +08:00
extendedStage('Local Docker Dev Build')
2021-04-15 22:42:07 +08:00
.hooks(buildSummaryReportHooks)
2021-04-13 09:12:09 +08:00
.required(env.GERRIT_PROJECT == 'canvas-lms' && buildConfig[FILES_CHANGED_STAGE].value('dockerDevFiles'))
.queue(nestedStages, jobName: '/Canvas/test-suites/local-docker-dev-smoke', buildParameters: buildParameters)
parallel(nestedStages)
2021-04-12 23:31:38 +08:00
}
2021-04-09 23:24:53 +08:00
2021-05-03 21:52:46 +08:00
extendedStage('Javascript (Waiting for Dependencies)').obeysAllowStages(false).waitsFor(JS_BUILD_IMAGE_STAGE, 'Builder').queue(rootStages) {
2021-04-13 09:12:09 +08:00
def nestedStages = [:]
extendedStage('Javascript (Jest)')
2021-04-15 22:42:07 +08:00
.hooks(buildSummaryReportHooks)
2021-04-13 09:12:09 +08:00
.queue(nestedStages, jobName: '/Canvas/test-suites/JS', buildParameters: buildParameters + [
string(name: 'KARMA_RUNNER_IMAGE', value: env.KARMA_RUNNER_IMAGE),
2021-05-03 21:52:46 +08:00
string(name: 'TEST_SUITE', value: 'jest'),
2021-04-13 09:12:09 +08:00
])
extendedStage('Javascript (Coffeescript)')
2021-04-15 22:42:07 +08:00
.hooks(buildSummaryReportHooks)
2021-04-13 09:12:09 +08:00
.queue(nestedStages, jobName: '/Canvas/test-suites/JS', buildParameters: buildParameters + [
string(name: 'KARMA_RUNNER_IMAGE', value: env.KARMA_RUNNER_IMAGE),
2021-05-03 21:52:46 +08:00
string(name: 'TEST_SUITE', value: 'coffee'),
2021-04-13 09:12:09 +08:00
])
extendedStage('Javascript (Karma)')
2021-04-15 22:42:07 +08:00
.hooks(buildSummaryReportHooks)
2021-04-13 09:12:09 +08:00
.queue(nestedStages, jobName: '/Canvas/test-suites/JS', buildParameters: buildParameters + [
string(name: 'KARMA_RUNNER_IMAGE', value: env.KARMA_RUNNER_IMAGE),
2021-05-03 21:52:46 +08:00
string(name: 'TEST_SUITE', value: 'karma'),
2021-04-13 09:12:09 +08:00
])
parallel(nestedStages)
2021-04-12 23:31:38 +08:00
}
2021-03-23 04:59:07 +08:00
2021-05-11 04:31:33 +08:00
extendedStage('Linters (Waiting for Dependencies)').obeysAllowStages(false).waitsFor(LINTERS_BUILD_IMAGE_STAGE, 'Builder').queue(rootStages) {
2021-05-11 21:20:41 +08:00
extendedStage('Linters - Dependency Check')
.hooks([onNodeAcquired: lintersStage.&setupNode])
.nodeRequirements(label: 'canvas-docker', podTemplate: libraryResource('/pod_templates/docker_base.yml'), container: 'docker')
.required(configuration.isChangeMerged())
.execute(lintersStage.&dependencyCheckStage)
2021-05-11 04:31:33 +08:00
extendedStage('Linters')
2021-05-11 21:20:41 +08:00
.hooks([onNodeAcquired: lintersStage.&setupNode, onNodeReleasing: lintersStage.&tearDownNode])
2021-05-11 04:31:33 +08:00
.nodeRequirements(label: 'canvas-docker', podTemplate: libraryResource('/pod_templates/docker_base.yml'), container: 'docker')
2021-05-11 07:46:14 +08:00
.required(!configuration.isChangeMerged())
2021-05-11 04:31:33 +08:00
.execute {
def nestedStages = [:]
2021-05-11 21:20:41 +08:00
extendedStage('Linters - Code')
.queue(nestedStages, lintersStage.&codeStage)
extendedStage('Linters - Master Bouncer')
.required(env.MASTER_BOUNCER_RUN == '1')
2021-05-11 04:31:33 +08:00
.queue(nestedStages, lintersStage.&masterBouncerStage)
2021-05-11 21:20:41 +08:00
extendedStage('Linters - Webpack')
.queue(nestedStages, lintersStage.&webpackStage)
extendedStage('Linters - Yarn')
2021-05-11 07:46:14 +08:00
.required(env.GERRIT_PROJECT == 'canvas-lms' && git.changedFiles(['package.json', 'yarn.lock'], 'HEAD^'))
2021-05-11 04:31:33 +08:00
.queue(nestedStages, lintersStage.&yarnStage)
parallel(nestedStages)
}
}
2021-04-13 09:12:09 +08:00
extendedStage("${RUN_MIGRATIONS_STAGE} (Waiting for Dependencies)").obeysAllowStages(false).waitsFor(RUN_MIGRATIONS_STAGE, 'Builder').queue(rootStages) { _, buildConfig ->
def nestedStages = [:]
extendedStage('CDC Schema Check')
2021-04-15 22:42:07 +08:00
.hooks(buildSummaryReportHooks)
2021-04-13 09:12:09 +08:00
.required(buildConfig[FILES_CHANGED_STAGE].value('migrationFiles'))
.queue(nestedStages, jobName: '/Canvas/cdc-event-transformer-master', buildParameters: buildParameters + [
string(name: 'CANVAS_LMS_IMAGE_PATH', value: "${env.PATCHSET_TAG}"),
])
extendedStage('Contract Tests')
2021-04-15 22:42:07 +08:00
.hooks(buildSummaryReportHooks)
2021-04-13 09:12:09 +08:00
.queue(nestedStages, jobName: '/Canvas/test-suites/contract-tests', buildParameters: buildParameters + [
string(name: 'CASSANDRA_IMAGE_TAG', value: "${env.CASSANDRA_IMAGE_TAG}"),
string(name: 'DYNAMODB_IMAGE_TAG', value: "${env.DYNAMODB_IMAGE_TAG}"),
string(name: 'POSTGRES_IMAGE_TAG', value: "${env.POSTGRES_IMAGE_TAG}"),
])
extendedStage('Flakey Spec Catcher')
2021-04-15 22:42:07 +08:00
.hooks(buildSummaryReportHooks)
2021-04-13 09:12:09 +08:00
.required(!configuration.isChangeMerged() && buildConfig[FILES_CHANGED_STAGE].value('specFiles') || configuration.forceFailureFSC() == '1')
.queue(nestedStages, jobName: '/Canvas/test-suites/flakey-spec-catcher', buildParameters: buildParameters + [
string(name: 'CASSANDRA_IMAGE_TAG', value: "${env.CASSANDRA_IMAGE_TAG}"),
string(name: 'DYNAMODB_IMAGE_TAG', value: "${env.DYNAMODB_IMAGE_TAG}"),
string(name: 'POSTGRES_IMAGE_TAG', value: "${env.POSTGRES_IMAGE_TAG}"),
])
extendedStage('Vendored Gems')
2021-04-15 22:42:07 +08:00
.hooks(buildSummaryReportHooks)
2021-04-13 09:12:09 +08:00
.queue(nestedStages, jobName: '/Canvas/test-suites/vendored-gems', buildParameters: buildParameters + [
string(name: 'CASSANDRA_IMAGE_TAG', value: "${env.CASSANDRA_IMAGE_TAG}"),
string(name: 'DYNAMODB_IMAGE_TAG', value: "${env.DYNAMODB_IMAGE_TAG}"),
string(name: 'POSTGRES_IMAGE_TAG', value: "${env.POSTGRES_IMAGE_TAG}"),
])
distribution.addRSpecSuites(nestedStages)
distribution.addSeleniumSuites(nestedStages)
parallel(nestedStages)
2021-04-12 23:31:38 +08:00
}
2021-04-13 09:12:09 +08:00
parallel(rootStages)
2021-04-10 01:36:02 +08:00
}
2020-08-22 03:42:49 +08:00
}//script
}//steps
}//environment
}//stages
2020-11-04 05:33:25 +08:00
}//pipeline