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-09-22 00:21:55 +08:00
2021-05-19 01:03:16 +08:00
final static JS_BUILD_IMAGE_STAGE = 'Javascript (Build Image)'
final static LINTERS_BUILD_IMAGE_STAGE = 'Linters (Build Image)'
final static RUN_MIGRATIONS_STAGE = 'Run Migrations'
2023-03-23 02:27:41 +08:00
final static BUILD_DOCKER_IMAGE_STAGE = 'Build Docker Image'
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}"),
2021-08-17 06:38:01 +08:00
string(name: 'GERRIT_CHANGE_SUBJECT', value: "${env.GERRIT_CHANGE_SUBJECT}"),
2019-08-15 02:43:09 +08:00
string(name: 'GERRIT_PATCHSET_NUMBER', value: "${env.GERRIT_PATCHSET_NUMBER}"),
2021-06-14 03:04:03 +08:00
string(name: 'GERRIT_PATCHSET_REVISION', value: "${env.GERRIT_PATCHSET_REVISION}"),
2019-08-15 02:43:09 +08:00
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}"),
2022-01-28 06:40:57 +08:00
string(name: 'MASTER_BOUNCER_RUN', value: "${env.MASTER_BOUNCER_RUN}"),
string(name: 'CRYSTALBALL_MAP_S3_VERSION', value: "${env.CRYSTALBALL_MAP_S3_VERSION}")
2019-08-15 02:43:09 +08:00
]
2023-03-15 01:05:59 +08:00
commitMessageFlag.setEnabled(env.GERRIT_EVENT_TYPE != 'change-merged')
2023-03-16 03:49:44 +08:00
library "canvas-builds-library@${getCanvasBuildsRefspec()}"
loadLocalLibrary('local-lib', 'build/new-jenkins/library')
2023-03-16 23:19:49 +08:00
commitMessageFlag.setDefaultValues(commitMessageFlagDefaults() + commitMessageFlagPrivateDefaults())
2023-03-16 03:49:44 +08:00
protectedNode.setReportUnhandledExceptions(!env.JOB_NAME.endsWith('Jenkinsfile'))
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() {
2022-01-19 09:58:11 +08:00
if (env.GERRIT_PROJECT == 'qti_migration_tool') {
return "/usr/src/app/vendor/${env.GERRIT_PROJECT}"
}
2022-09-26 20:12:57 +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() {
2022-01-19 05:53:34 +08:00
if (env.GERRIT_PROJECT == 'qti_migration_tool') {
return "vendor/${env.GERRIT_PROJECT}"
}
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-02-15 06:02:23 +08:00
def isPatchsetPublishable() {
2023-03-17 03:06:51 +08:00
env.PUBLISH_PATCHSET_IMAGE == "1"
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')
}
2021-11-05 01:34:07 +08:00
def isStartedByUser() {
return currentBuild.getBuildCauses('hudson.model.Cause$UserIdCause')
}
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)
2022-03-09 20:58:59 +08:00
dockerUtils.tagRemote(env.KARMA_RUNNER_IMAGE, env.KARMA_MERGE_IMAGE)
2020-11-03 09:34:07 +08:00
}
2021-11-05 01:34:07 +08:00
if (isStartedByUser()) {
2023-03-13 21:13:55 +08:00
submitGerritReview((status == 'SUCCESS' ? '--verified +1' : '--verified -1'), "${env.BUILD_URL}/build-summary-report/")
2021-11-05 01:34:07 +08:00
}
2020-11-03 09:34:07 +08:00
}
2022-06-11 00:26:49 +08:00
build(job: "/Canvas/helpers/junit-uploader", parameters: [
string(name: 'GERRIT_REFSPEC', value: "${env.GERRIT_REFSPEC}"),
string(name: 'GERRIT_EVENT_TYPE', value: "${env.GERRIT_EVENT_TYPE}"),
string(name: 'SOURCE', value: "${env.JOB_NAME}/${env.BUILD_NUMBER}"),
], propagate: false, wait: false)
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' && (
2023-03-16 00:13:47 +08:00
configuration.isChangeMerged() && (commitMessageFlag('enable-automatic-retrigger') as Boolean)
2020-09-03 22:31:09 +08:00
)
}
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()) {
2021-08-25 01:15:01 +08:00
def extra = 'Oh no! Your build failed the post-merge checks. If you have a test failure not related to your build, please reach out to the owning team and ask them to skip or fix the failed test. Spec flakiness can be investigated <https://inst.splunkcloud.com/en-US/app/search/canvas_spec_tracker|here>. Otherwise, tag our @ oncall for help in diagnosing the build issue if it is unclear.'
2022-07-26 03:34:03 +08:00
slackHelpers.sendSlackFailureWithMsg(getSlackChannel(), extra, true)
} else {
slackHelpers.sendSlackFailureWithDuration('#canvas_builds-noisy')
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()) {
2023-02-02 23:08:35 +08:00
def patchsetPrefix = env.GERRIT_CHANGE_URL ? "Patchset <${env.GERRIT_CHANGE_URL}|#${env.GERRIT_CHANGE_NUMBER}>" : env.JOB_NAME
2020-09-02 22:46:17 +08:00
slackSend(
channel: getSlackChannel(),
color: 'good',
2023-02-02 23:08:35 +08:00
message: "${patchsetPrefix} 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',
2022-06-03 02:49:22 +08:00
message: "${env.JOB_NAME} <${getSummaryUrl()}|#${env.BUILD_NUMBER}> succeeded. Patchset <${env.GERRIT_CHANGE_URL}|#${env.GERRIT_CHANGE_NUMBER}>. (${currentBuild.durationString})"
2021-04-13 05:26:12 +08:00
)
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()) {
2023-02-02 23:08:35 +08:00
def patchsetPrefix = env.GERRIT_CHANGE_URL ? "Patchset <${env.GERRIT_CHANGE_URL}|#${env.GERRIT_CHANGE_NUMBER}>" : env.JOB_NAME
2020-09-02 01:18:16 +08:00
slackSend(
channel: getSlackChannel(),
color: 'warning',
2023-02-02 23:08:35 +08:00
message: "${patchsetPrefix} 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
)
}
}
2021-11-05 01:34:07 +08:00
@groovy.transform.Field final static GERRIT_CHANGE_ID_REGEX = /Change\-Id: (.*)/
def getChangeId() {
if (env.GERRIT_CHANGE_ID) {
return env.GERRIT_CHANGE_ID
}
def commitMessage = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : null
if (!commitMessage) {
error 'GERRIT_CHANGE_COMMIT_MESSAGE not found! You must provide a commit message!'
}
return (commitMessage =~ GERRIT_CHANGE_ID_REGEX).findAll()[0][1]
}
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() {
2022-09-28 03:51:41 +08:00
return env.SLACK_CHANNEL_OVERRIDE ?: 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
def getCanvasBuildsRefspec() {
2023-03-14 23:31:38 +08:00
def defaultValue = env.GERRIT_BRANCH.contains('stable/') ? env.GERRIT_BRANCH : 'master'
2020-11-02 23:39:02 +08:00
2023-03-14 23:31:38 +08:00
return commitMessageFlag('canvas-builds-refspec') as String ?: defaultValue
2020-11-02 23:39:02 +08:00
}
2020-10-08 22:19:24 +08:00
def getCanvasLmsRefspec() {
2023-03-14 23:31:38 +08:00
def defaultBranch = env.GERRIT_BRANCH.contains('stable/') ? env.GERRIT_BRANCH : 'master'
def defaultValue = "+refs/heads/$defaultBranch:refs/remotes/origin/$defaultBranch"
2021-09-20 23:18:53 +08:00
2023-03-14 23:31:38 +08:00
return commitMessageFlag('canvas-lms-refspec') as String ?: defaultValue
2020-10-08 22:19:24 +08:00
}
2020-08-05 05:42:10 +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-11-17 03:00:54 +08:00
timeout(time: 8, 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()
2023-03-16 03:49:44 +08:00
RSPEC_PROCESSES = commitMessageFlag('rspecq-processes').asType(Integer)
2021-11-05 01:34:07 +08:00
GERRIT_CHANGE_ID = getChangeId()
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
// 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
RUBY = configuration.ruby() // RUBY_VERSION is a reserved keyword for ruby installs
2020-06-27 03:37:32 +08:00
2023-03-16 00:13:47 +08:00
FORCE_CRYSTALBALL = "${commitMessageFlag('force-crystalball').asBooleanInteger()}"
2022-10-18 22:27:43 +08:00
2021-11-30 00:15:30 +08:00
BASE_RUNNER_PREFIX = configuration.buildRegistryPath('base-runner')
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_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')
2022-09-21 00:30:53 +08:00
WEBPACK_ASSETS_PREFIX = configuration.buildRegistryPath('webpack-assets')
2022-09-27 05:07:08 +08:00
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"
2022-09-21 00:30:53 +08:00
WEBPACK_ASSETS_IMAGE = "$WEBPACK_ASSETS_PREFIX:$IMAGE_CACHE_UNIQUE_SCOPE"
2020-12-03 01:02:24 +08:00
2021-10-05 04:20:02 +08:00
CASSANDRA_MERGE_IMAGE = "$CASSANDRA_PREFIX:$IMAGE_CACHE_MERGE_SCOPE-${env.RSPEC_PROCESSES ?: '4'}"
DYNAMODB_MERGE_IMAGE = "$DYNAMODB_PREFIX:$IMAGE_CACHE_MERGE_SCOPE-${env.RSPEC_PROCESSES ?: '4'}"
2021-02-02 01:47:21 +08:00
KARMA_RUNNER_IMAGE = "$KARMA_RUNNER_PREFIX:$IMAGE_CACHE_UNIQUE_SCOPE"
2022-03-09 20:58:59 +08:00
KARMA_MERGE_IMAGE = "$KARMA_RUNNER_PREFIX:$IMAGE_CACHE_MERGE_SCOPE"
2021-05-11 02:59:51 +08:00
LINTERS_RUNNER_IMAGE = "$LINTERS_RUNNER_PREFIX:$IMAGE_CACHE_UNIQUE_SCOPE"
2021-10-05 04:20:02 +08:00
POSTGRES_MERGE_IMAGE = "$POSTGRES_PREFIX:$IMAGE_CACHE_MERGE_SCOPE-${env.RSPEC_PROCESSES ?: '4'}"
2021-01-20 03:15:52 +08:00
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()
2021-11-03 00:48:37 +08:00
// TEST_CACHE_CLASSES is consumed by config/environments/test.rb
// to decide whether to allow class reloading or not.
// in local development we usually want this unset or set to '0' because
// we want spring to be able to reload classes between
// spec runs, but this is expensive when running all the
// specs for the build. EVERYWHERE in the build we want
// to be able to cache classes because they don't change while the build
// is running and should never be reloaded.
TEST_CACHE_CLASSES = '1'
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-11-17 03:00:54 +08:00
lock(label: 'canvas_build_global_mutex', quantity: 1) {
timeout(60) {
2022-08-22 22:29:02 +08:00
// Skip translation builds for patchsets uploaded by svc.cloudjenkins
if (env.GERRIT_PATCHSET_UPLOADER_EMAIL == 'svc.cloudjenkins@instructure.com' && env.GERRIT_CHANGE_SUBJECT =~ /translation$/) {
2022-10-12 01:16:55 +08:00
// Set status to NOT_BUILT for pre-merge builds
if (!configuration.isChangeMerged()) {
currentBuild.result = 'NOT_BUILT'
}
2022-08-22 22:29:02 +08:00
return
}
2021-11-17 03:00:54 +08:00
node('master') {
2022-03-07 23:47:27 +08:00
// For builds like Rails 6.1 prototype, we want to be able to see the build link, but
// not have Gerrit vote on it. This isn't currently supported through the Gerrit Trigger
// plugin, because the Build Started message always votes and will clear the original
// vote. Work around this by disabling the build start message and setting EMULATE_BUILD_START=1
// in the Build Parameters section.
// https://issues.jenkins.io/browse/JENKINS-28339
2023-03-16 00:13:47 +08:00
if (commitMessageFlag("emulate-build-start") as Boolean) {
2023-03-13 21:13:55 +08:00
submitGerritReview("", "Build Started ${RUN_DISPLAY_URL}")
2022-03-07 23:47:27 +08:00
}
2023-03-17 02:00:28 +08:00
if (commitMessageFlag("skip-ci") as Boolean) {
2021-11-17 03:00:54 +08:00
currentBuild.result = 'NOT_BUILT'
2023-03-13 21:13:55 +08:00
submitGerritReview('--label Lint-Review=-2', 'Build not executed due to [skip-ci] flag')
2021-11-17 03:00:54 +08:00
error '[skip-ci] flag enabled: skipping the build'
return
} else if (extendedStage.isAllowStagesFilterUsed() || extendedStage.isIgnoreStageResultsFilterUsed() || extendedStage.isSkipStagesFilterUsed()) {
2023-03-13 21:13:55 +08:00
submitGerritReview('--label Lint-Review=-2', 'One or more build flags causes a subset of the build to be run')
2022-03-08 22:10:33 +08:00
} else if (setupStage.hasGemOverrides()) {
2023-09-26 04:30:00 +08:00
submitGerritReview('--label Lint-Review=-2', 'One or more build flags causes the build to be run against an unmerged gem or plugin version; if you need to coordinate merging multiple changes at once, you may want to edit the commit message to remove this flag after Jenkins has run tests')
2021-11-17 03:00:54 +08:00
} else {
2023-03-13 21:13:55 +08:00
submitGerritReview('--label Lint-Review=0')
2021-11-17 03:00:54 +08:00
}
}
2020-09-02 01:18:16 +08:00
2021-11-17 03:00:54 +08:00
if (isStartedByUser()) {
env.GERRIT_PATCHSET_REVISION = git.getRevisionHash()
buildParameters += string(name: 'GERRIT_PATCHSET_REVISION', value: "${env.GERRIT_PATCHSET_REVISION}")
2021-04-21 06:29:56 +08:00
}
2021-04-15 22:42:07 +08:00
2021-11-17 03:00:54 +08:00
// Ensure that all build flags are compatible.
2023-03-17 03:49:36 +08:00
if (commitMessageFlag('change-merged') as Boolean && configuration.buildRegistryPath() == configuration.buildRegistryPathDefault()) {
2021-11-17 03:00:54 +08:00
error 'Manually triggering the change-merged build path must be combined with a custom build-registry-path'
return
}
2021-03-23 05:36:59 +08:00
2021-11-17 03:00:54 +08:00
maybeSlackSendRetrigger()
2021-04-12 23:31:38 +08:00
2021-11-17 03:00:54 +08:00
def postBuildHandler = [
2021-12-01 02:56:25 +08:00
onStageEnded: { stageName, stageConfig, result ->
2021-11-17 03:00:54 +08:00
buildSummaryReport.addFailureRun('Main Build', currentBuild)
postFn(stageConfig.status())
}
]
2021-11-30 23:51:44 +08:00
extendedStage('Root').hooks(postBuildHandler).obeysAllowStages(false).reportTimings(false).execute {
2021-11-17 03:00:54 +08:00
def rootStages = [:]
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}")
2022-03-24 04:16:20 +08:00
buildParameters += string(name: 'CANVAS_RAILS', value: "${env.CANVAS_RAILS}")
2021-11-17 03:00:54 +08:00
// If modifying any of our Jenkinsfiles set JENKINSFILE_REFSPEC for sub-builds to use Jenkinsfiles in
// the gerrit rather than master. Stable branches also need to check out the JENKINSFILE_REFSPEC to prevent
// the job default from pulling master.
if (env.GERRIT_PROJECT == 'canvas-lms' && env.JOB_NAME.endsWith('Jenkinsfile')) {
buildParameters += string(name: 'JENKINSFILE_REFSPEC', value: "${env.GERRIT_REFSPEC}")
} else if (env.GERRIT_PROJECT == 'canvas-lms' && env.JOB_NAME.endsWith('stable')) {
buildParameters += string(name: 'JENKINSFILE_REFSPEC', value: "${env.GERRIT_REFSPEC}")
2021-10-28 04:42:26 +08:00
}
2021-11-17 03:00:54 +08:00
if (env.GERRIT_PROJECT != 'canvas-lms') {
// 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-14 22:13:42 +08:00
2023-03-17 02:46:17 +08:00
extendedStage('Builder').nodeRequirements(label: nodeLabel(), podTemplate: null).obeysAllowStages(false).reportTimings(false).queue(rootStages) {
2021-11-17 03:00:54 +08:00
extendedStage('Setup')
2021-12-01 02:22:05 +08:00
.hooks(buildSummaryReportHooks.call())
2021-11-17 03:00:54 +08:00
.obeysAllowStages(false)
.timeout(2)
2022-09-23 03:52:35 +08:00
.execute {
buildDockerImageStage.preloadCacheImagesAsync()
setupStage()
}
2021-11-17 03:00:54 +08:00
extendedStage('Rebase')
2021-12-01 02:22:05 +08:00
.hooks(buildSummaryReportHooks.call())
2021-11-17 03:00:54 +08:00
.obeysAllowStages(false)
.required(!configuration.isChangeMerged() && env.GERRIT_PROJECT == 'canvas-lms')
.timeout(2)
.execute { rebaseStage() }
extendedStage(filesChangedStage.STAGE_NAME)
2021-12-01 02:22:05 +08:00
.hooks(buildSummaryReportHooks.call())
2021-11-17 03:00:54 +08:00
.obeysAllowStages(false)
.timeout(2)
2022-07-29 02:51:08 +08:00
.execute(filesChangedStage.&preBuild)
2021-11-17 03:00:54 +08:00
extendedStage('Build Docker Image (Pre-Merge)')
2021-12-01 02:22:05 +08:00
.hooks(buildSummaryReportHooks.call())
2021-11-17 03:00:54 +08:00
.obeysAllowStages(false)
.required(configuration.isChangeMerged())
.timeout(20)
.execute(buildDockerImageStage.&premergeCacheImage)
2023-03-23 02:27:41 +08:00
extendedStage(BUILD_DOCKER_IMAGE_STAGE)
2021-12-01 02:22:05 +08:00
.hooks(buildSummaryReportHooks.call())
2021-11-17 03:00:54 +08:00
.obeysAllowStages(false)
.timeout(20)
2022-06-23 03:28:13 +08:00
.execute {
2022-06-23 21:58:19 +08:00
def startStep = '''
2022-06-23 10:52:30 +08:00
docker run -dt --name general-build-container --volume $(pwd)/$LOCAL_WORKDIR/.git:$DOCKER_WORKDIR/.git -e RAILS_ENV=test $PATCHSET_TAG bash -c "sleep infinity"
docker exec -dt general-build-container bin/rails graphql:schema
2022-06-23 21:58:19 +08:00
'''
2023-05-25 21:10:38 +08:00
@SuppressWarnings('GStringExpressionWithinString')
2022-06-23 21:58:19 +08:00
def crystalballStep = '''
diffFrom=$(git --git-dir $LOCAL_WORKDIR/.git rev-parse $GERRIT_PATCHSET_REVISION^1)
2023-05-25 21:10:38 +08:00
# crystalball will fail without adding $DOCKER_WORKDIR to safe.directory
docker exec -t general-build-container bash -c "git config --global --add safe.directory ${DOCKER_WORKDIR%/}"
2022-06-23 21:58:19 +08:00
docker exec -dt \
-e CRYSTALBALL_DIFF_FROM=$diffFrom \
-e CRYSTALBALL_DIFF_TO=$GERRIT_PATCHSET_REVISION \
-e CRYSTALBALL_REPO_PATH=$DOCKER_WORKDIR \
2022-10-18 22:27:43 +08:00
-e FORCE_CRYSTALBALL=$FORCE_CRYSTALBALL \
2022-06-23 21:58:19 +08:00
general-build-container bundle exec crystalball --dry-run
'''
def finalStep = '''
2022-06-23 03:28:13 +08:00
docker exec -t general-build-container ps aww
2022-06-23 21:58:19 +08:00
'''
def asyncSteps = [
startStep,
!configuration.isChangeMerged() && env.GERRIT_REFSPEC != 'refs/heads/master' ? crystalballStep : '',
finalStep
]
buildDockerImageStage.patchsetImage(asyncSteps.join("\n"))
2022-06-23 03:28:13 +08:00
}
2021-11-17 03:00:54 +08:00
2022-07-29 02:51:08 +08:00
extendedStage(filesChangedStage.STAGE_NAME_POST_BUILD)
.hooks(buildSummaryReportHooks.call())
.obeysAllowStages(false)
.timeout(2)
.execute(filesChangedStage.&postBuild)
2021-11-17 03:00:54 +08:00
extendedStage(RUN_MIGRATIONS_STAGE)
2021-12-01 02:22:05 +08:00
.hooks(buildSummaryReportHooks.call())
2021-11-17 03:00:54 +08:00
.obeysAllowStages(false)
.timeout(10)
.execute { runMigrationsStage() }
2022-01-13 03:01:15 +08:00
extendedStage('Generate Crystalball Prediction')
.hooks(buildSummaryReportHooks.call())
.obeysAllowStages(false)
2022-03-18 02:00:16 +08:00
.required(!configuration.isChangeMerged() && env.GERRIT_REFSPEC != "refs/heads/master")
2022-01-13 03:01:15 +08:00
.timeout(2)
.execute {
2022-01-14 00:39:52 +08:00
try {
/* groovylint-disable-next-line GStringExpressionWithinString */
2022-06-23 03:28:13 +08:00
sh '''#!/bin/bash
set -ex
while docker exec -t general-build-container ps aww | grep crystalball; do
sleep 0.1
done
2023-05-24 21:29:38 +08:00
docker exec -t general-build-container bash -c 'cat log/crystalball.log'
2022-06-23 03:28:13 +08:00
docker cp \$(docker ps -qa -f name=general-build-container):/usr/src/app/crystalball_spec_list.txt ./tmp/crystalball_spec_list.txt
2022-01-14 00:39:52 +08:00
'''
archiveArtifacts allowEmptyArchive: true, artifacts: 'tmp/crystalball_spec_list.txt'
2022-01-25 04:18:53 +08:00
sh 'grep ":timestamp:" crystalball_map.yml | sed "s/:timestamp: //g" > ./tmp/crystalball_map_version.txt'
archiveArtifacts allowEmptyArchive: true, artifacts: 'tmp/crystalball_map_version.txt'
2022-01-14 00:39:52 +08:00
/* groovylint-disable-next-line CatchException */
} catch (Exception e) {
2022-03-23 03:22:59 +08:00
// default to full run of specs
sh 'echo -n "." > tmp/crystalball_spec_list.txt'
sh 'echo -n "broken map, defaulting to run all tests" > tmp/crystalball_map_version.txt'
archiveArtifacts allowEmptyArchive: true, artifacts: 'tmp/crystalball_spec_list.txt, tmp/crystalball_map_version.txt'
slackSend(
channel: '#crystalball-noisy',
color: 'danger',
message: "${env.JOB_NAME} <${getSummaryUrl()}|#${env.BUILD_NUMBER}>\n\nFailed to generate prediction!"
)
2022-01-14 00:39:52 +08:00
}
2022-01-13 03:01:15 +08:00
}
2022-04-12 22:45:03 +08:00
extendedStage('Locales Only Changes')
.hooks(buildSummaryReportHooks.call())
.obeysAllowStages(false)
2022-05-10 00:36:37 +08:00
.required(!configuration.isChangeMerged() && env.GERRIT_PROJECT == 'canvas-lms' && sh(script: "${WORKSPACE}/build/new-jenkins/locales-changes.sh", returnStatus: true) == 0)
2022-04-12 22:45:03 +08:00
.execute {
2023-03-13 21:13:55 +08:00
submitGerritReview('--label Lint-Review=-2', 'This commit contains only changes to config/locales/, this could be a bad sign!')
2022-04-12 22:45:03 +08:00
}
2022-04-14 22:18:11 +08:00
extendedStage('Webpack Bundle Size Check')
.hooks(buildSummaryReportHooks.call())
.obeysAllowStages(false)
.required(configuration.isChangeMerged())
.timeout(20)
.execute { webpackStage.&calcBundleSizes() }
2021-11-17 03:00:54 +08:00
extendedStage('Parallel Run Tests').obeysAllowStages(false).execute { stageConfig, buildConfig ->
def stages = [:]
2021-12-01 02:22:05 +08:00
extendedStage('Consumer Smoke Test').hooks(buildSummaryReportHooks.call()).queue(stages) {
2021-11-17 03:00:54 +08:00
sh 'build/new-jenkins/consumer-smoke-test.sh'
}
2023-03-17 02:00:28 +08:00
def shouldRunJS = configuration.isChangeMerged() || commitMessageFlag('force-failure-js') as Boolean ||
2022-07-29 02:51:08 +08:00
(!configuration.isChangeMerged() && (filesChangedStage.hasGraphqlFiles(buildConfig) || filesChangedStage.hasJsFiles(buildConfig)))
2021-11-17 03:00:54 +08:00
extendedStage(JS_BUILD_IMAGE_STAGE)
2021-12-01 02:22:05 +08:00
.hooks(buildSummaryReportHooks.call())
2022-07-29 02:51:08 +08:00
.required(shouldRunJS)
2021-11-17 03:00:54 +08:00
.queue(stages, buildDockerImageStage.&jsImage)
extendedStage(LINTERS_BUILD_IMAGE_STAGE)
2021-12-01 02:22:05 +08:00
.hooks(buildSummaryReportHooks.call())
2021-11-17 03:00:54 +08:00
.queue(stages, buildDockerImageStage.&lintersImage)
2022-06-19 16:29:02 +08:00
extendedStage('Run i18n:extract')
2021-12-01 02:22:05 +08:00
.hooks(buildSummaryReportHooks.call())
2021-10-13 00:29:06 +08:00
.required(configuration.isChangeMerged())
2022-06-19 16:29:02 +08:00
.queue(stages, buildDockerImageStage.&i18nExtract)
2021-10-13 00:29:06 +08:00
2021-11-17 03:00:54 +08:00
parallel(stages)
}
}
2021-05-11 04:31:33 +08:00
2023-03-23 02:27:41 +08:00
extendedStage('ARM64 Builder - Container')
2023-03-09 22:57:40 +08:00
.hooks(buildSummaryReportHooks.call())
.nodeRequirements(label: 'docker-arm64')
.required(configuration.isChangeMerged())
.queue(rootStages) {
2023-03-23 02:27:41 +08:00
extendedStage('ARM64 Builder').execute {
setupStage()
// Rebase is fortunately not needed - since this only runs in post-merge
buildDockerImageStage.patchsetImage('', '-arm64')
}
extendedStage('Augment Manifest').waitsFor(BUILD_DOCKER_IMAGE_STAGE, 'Builder').execute {
sh """#!/bin/bash -ex
docker manifest create --amend $PATCHSET_TAG $PATCHSET_TAG $PATCHSET_TAG-arm64
docker manifest push $PATCHSET_TAG
"""
}
2023-03-09 22:57:40 +08:00
}
2021-11-17 03:00:54 +08:00
extendedStage("${filesChangedStage.STAGE_NAME} (Waiting for Dependencies)").obeysAllowStages(false).waitsFor(filesChangedStage.STAGE_NAME, 'Builder').queue(rootStages) { stageConfig, buildConfig ->
def nestedStages = [:]
2021-04-13 09:12:09 +08:00
2021-11-17 03:00:54 +08:00
extendedStage('Local Docker Dev Build')
2021-12-01 02:22:05 +08:00
.hooks(buildSummaryReportHooks.call())
2021-11-17 03:00:54 +08:00
.required(env.GERRIT_PROJECT == 'canvas-lms' && filesChangedStage.hasDockerDevFiles(buildConfig))
.queue(nestedStages, jobName: '/Canvas/test-suites/local-docker-dev-smoke', buildParameters: buildParameters)
2021-04-09 23:24:53 +08:00
2021-11-17 03:00:54 +08:00
parallel(nestedStages)
}
2021-04-13 09:12:09 +08:00
2021-11-17 03:00:54 +08:00
extendedStage('Javascript (Waiting for Dependencies)').obeysAllowStages(false).waitsFor(JS_BUILD_IMAGE_STAGE, 'Builder').queue(rootStages) {
def nestedStages = [:]
2021-04-09 23:24:53 +08:00
2021-11-17 03:00:54 +08:00
extendedStage('Javascript')
2022-06-01 09:27:33 +08:00
.hooks(buildSummaryReportHooks.withRunManifest(true))
2021-11-17 03:00:54 +08:00
.queue(nestedStages, jobName: '/Canvas/test-suites/JS', buildParameters: buildParameters + [
string(name: 'KARMA_RUNNER_IMAGE', value: env.KARMA_RUNNER_IMAGE),
])
2021-04-13 09:12:09 +08:00
2021-11-17 03:00:54 +08:00
parallel(nestedStages)
}
2021-04-13 09:12:09 +08:00
2021-11-17 03:00:54 +08:00
extendedStage('Linters (Waiting for Dependencies)').obeysAllowStages(false).waitsFor(LINTERS_BUILD_IMAGE_STAGE, 'Builder').queue(rootStages) { stageConfig, buildConfig ->
extendedStage('Linters - Dependency Check')
2023-03-17 02:46:17 +08:00
.nodeRequirements(label: nodeLabel(), podTemplate: dependencyCheckStage.nodeRequirementsTemplate(), container: 'dependency-check')
2021-11-17 03:00:54 +08:00
.required(configuration.isChangeMerged())
.execute(dependencyCheckStage.queueTestStage())
extendedStage('Linters')
.hooks([onNodeReleasing: lintersStage.tearDownNode()])
2023-03-17 02:46:17 +08:00
.nodeRequirements(label: nodeLabel(), podTemplate: lintersStage.nodeRequirementsTemplate())
2022-03-21 23:02:25 +08:00
.required(!configuration.isChangeMerged() && env.GERRIT_CHANGE_ID != '0')
2021-11-17 03:00:54 +08:00
.execute {
def nestedStages = [:]
2023-01-31 00:55:53 +08:00
callableWithDelegate(lintersStage.bundleStage(nestedStages, buildConfig))()
2021-11-17 03:00:54 +08:00
callableWithDelegate(lintersStage.codeStage(nestedStages))()
callableWithDelegate(lintersStage.masterBouncerStage(nestedStages))()
callableWithDelegate(lintersStage.yarnStage(nestedStages, buildConfig))()
parallel(nestedStages)
}
}
2021-03-23 04:59:07 +08:00
2021-11-17 03:00:54 +08:00
extendedStage("${RUN_MIGRATIONS_STAGE} (Waiting for Dependencies)").obeysAllowStages(false).waitsFor(RUN_MIGRATIONS_STAGE, 'Builder').queue(rootStages) { stageConfig, buildConfig ->
2021-05-11 04:31:33 +08:00
def nestedStages = [:]
2021-11-17 03:00:54 +08:00
extendedStage('Contract Tests')
2021-12-01 02:22:05 +08:00
.hooks(buildSummaryReportHooks.call())
2021-11-17 03:00:54 +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}"),
])
2022-03-23 03:04:41 +08:00
// Trigger Crystalball map build if spec files were added or removed, will not vote on builds.
2024-04-25 04:38:25 +08:00
// Only trigger for main-postmerge job.
if (env.JOB_NAME == "Canvas/main-postmerge" && configuration.isChangeMerged() && filesChangedStage.hasNewDeletedSpecFiles(buildConfig)) {
2022-03-24 21:21:30 +08:00
build(wait: false, job: 'Canvas/helpers/crystalball-map')
2022-03-23 03:04:41 +08:00
}
2021-11-17 03:00:54 +08:00
extendedStage('Flakey Spec Catcher')
2021-12-01 02:22:05 +08:00
.hooks(buildSummaryReportHooks.call())
2023-03-17 02:00:28 +08:00
.required(!configuration.isChangeMerged() && filesChangedStage.hasSpecFiles(buildConfig) || commitMessageFlag('force-failure-fsc') as Boolean)
2021-11-17 03:00:54 +08:00
.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-12-01 02:22:05 +08:00
.hooks(buildSummaryReportHooks.call())
2021-11-17 03:00:54 +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}"),
])
2022-01-08 02:04:49 +08:00
extendedStage('RspecQ Tests')
.hooks(buildSummaryReportHooks.withRunManifest())
.queue(nestedStages, jobName: '/Canvas/test-suites/test-queue', 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}"),
2022-03-08 22:10:33 +08:00
string(name: 'SKIP_CRYSTALBALL', value: "${env.SKIP_CRYSTALBALL || setupStage.hasGemOverrides()}"),
2022-01-20 23:40:48 +08:00
string(name: 'UPSTREAM_TAG', value: "${env.BUILD_TAG}"),
2022-02-02 03:47:56 +08:00
string(name: 'UPSTREAM', value: "${env.JOB_NAME}"),
2022-01-08 02:04:49 +08:00
])
2021-05-15 03:53:39 +08:00
2021-05-11 04:31:33 +08:00
parallel(nestedStages)
}
2021-11-17 03:00:54 +08:00
parallel(rootStages)
}
2021-04-12 23:31:38 +08:00
}
2021-04-10 01:36:02 +08:00
}
2022-04-19 02:50:37 +08:00
} // script
} // steps
} // environment
} // stages
} // pipeline