-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathJenkinsfile.crystalball
More file actions
250 lines (222 loc) · 9.83 KB
/
Jenkinsfile.crystalball
File metadata and controls
250 lines (222 loc) · 9.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#!/usr/bin/env groovy
/*
* Copyright (C) 2021 - 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/>.
*/
library 'canvas-builds-library'
loadLocalLibrary('local-lib', 'build/new-jenkins/library')
commitMessageFlag.setDefaultValues(commitMessageFlagDefaults() + commitMessageFlagPrivateDefaults())
@groovy.transform.Field
def rspecqNodeTotal = 50
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()
}
def getResultsHTMLUrl() {
return "${env.BUILD_URL}/artifact/crystalball_map.yml"
}
def sendCrystalballSlack(status) {
def message = ":alert: <$env.BUILD_URL|Crystalball Map Build> ${status}! :alert:\nResolve this issue to prevent further build failures!"
slackSend channel: '#crystalball-noisy,#devx-alerts', color: 'danger', message: message
}
def redisUrl() {
return "redis://${env.TEST_QUEUE_HOST}:6379"
}
def collectCrystalballMap() {
stage('Collect Crystalball Map') {
copyArtifacts(
filter: 'tmp/*/crystalball/**',
optional: true,
projectName: env.JOB_NAME,
selector: specific(env.BUILD_NUMBER),
)
sh """
docker compose run -v \$(pwd)/\$LOCAL_WORKDIR/tmp/:/tmp \
-v \$(pwd)/\$LOCAL_WORKDIR/build:/usr/src/app/build \
--name crystalball-parser \
canvas bash -c 'ruby build/new-jenkins/crystalball_merge_coverage.rb "/tmp/*/crystalball/"'
"""
sh 'docker cp crystalball-parser:/usr/src/app/crystalball_map.yml .'
archiveArtifacts allowEmptyArchive: true, artifacts: 'crystalball_map.yml'
def message = "<$env.BUILD_URL/testReport|Latest Crystalball Map Generated> - <${getResultsHTMLUrl()}|Map>\n"
try {
def mapSpecInfo = sh(script: """
docker compose run --rm \
-v \$(pwd)/\$LOCAL_WORKDIR/crystalball_map.yml/:/usr/src/app/crystalball_map.yml \
-v \$(pwd)/\$LOCAL_WORKDIR/build:/usr/src/app/build \
-v \$(pwd)/\$LOCAL_WORKDIR/gems/plugins/:/usr/src/app/gems/plugins \
-v \$(pwd)/\$LOCAL_WORKDIR/spec:/usr/src/app/spec \
canvas bash -c 'ruby build/new-jenkins/crystalball_map_smoke_test.rb'
"""
, returnStdout: true)
message = message + "\n" + mapSpecInfo
// Only alert and push to s3 on periodic jobs, not ones resulting from manual tests
if (env.CRYSTALBALL_MAP_PUSH_TO_S3 == '1' && env.GERRIT_EVENT_TYPE != 'comment-added') {
withCredentials([usernamePassword(credentialsId: 'INSENG_CANVAS_CI_AWS_ACCESS', usernameVariable: 'INSENG_AWS_ACCESS_KEY_ID', passwordVariable: 'INSENG_AWS_SECRET_ACCESS_KEY')]) {
def awsCreds = "AWS_DEFAULT_REGION=us-west-2 AWS_ACCESS_KEY_ID=${INSENG_AWS_ACCESS_KEY_ID} AWS_SECRET_ACCESS_KEY=${INSENG_AWS_SECRET_ACCESS_KEY}"
sh "$awsCreds aws s3 cp crystalball_map.yml s3://instructure-canvas-ci/"
}
}
} catch(e) {
message = message + "\nMap Invalid!"
} finally {
echo message
slackSend channel: '#crystalball-noisy', message: message
}
}
}
env.BUILD_REGISTRY_FQDN = configuration.buildRegistryFQDN()
env.COMPOSE_FILE = 'docker-compose.new-jenkins.yml:docker-compose.new-jenkins-selenium.yml'
env.COMPOSE_PROJECT_NAME = 'crystalball-map'
env.FORCE_FAILURE = commitMessageFlag("force-failure-rspec").asBooleanInteger()
env.RERUNS_RETRY = commitMessageFlag('rspecq-max-requeues').asType(Integer)
env.RSPECQ_FILE_SPLIT_THRESHOLD = '9999'
env.RSPECQ_MAX_REQUEUES = commitMessageFlag('rspecq-max-requeues').asType(Integer)
env.RSPEC_PROCESSES = commitMessageFlag('rspecq-processes').asType(Integer)
env.TEST_PATTERN = '^./(spec|gems/plugins/.*/spec_canvas)/'
env.POSTGRES_PASSWORD = 'sekret'
env.POSTGRES = configuration.postgres()
env.RUBY = configuration.ruby()
env.PATCHSET_TAG = getPatchsetTag()
env.BASE_RUNNER_PREFIX = configuration.buildRegistryPath('base-runner')
env.DYNAMODB_PREFIX = configuration.buildRegistryPath('dynamodb-migrations')
env.KARMA_RUNNER_PREFIX = configuration.buildRegistryPath('karma-runner')
env.LINTERS_RUNNER_PREFIX = configuration.buildRegistryPath('linters-runner')
env.POSTGRES_PREFIX = configuration.buildRegistryPath('postgres-migrations')
env.RUBY_RUNNER_PREFIX = configuration.buildRegistryPath('ruby-runner')
env.YARN_RUNNER_PREFIX = configuration.buildRegistryPath('yarn-runner')
env.WEBPACK_BUILDER_PREFIX = configuration.buildRegistryPath('webpack-builder')
env.WEBPACK_ASSETS_PREFIX = configuration.buildRegistryPath('webpack-assets')
env.IMAGE_CACHE_MERGE_SCOPE = configuration.gerritBranchSanitized()
env.DYNAMODB_IMAGE_TAG = "$env.DYNAMODB_PREFIX:$env.IMAGE_CACHE_MERGE_SCOPE-$env.RSPEC_PROCESSES"
env.POSTGRES_IMAGE_TAG = "$env.POSTGRES_PREFIX:$env.IMAGE_CACHE_MERGE_SCOPE-$env.RSPEC_PROCESSES"
env.POSTGRES_CLIENT = configuration.postgresClient()
env.RSPECQ_REDIS_URL = redisUrl()
env.LOCAL_WORKDIR = pipelineHelpers.getLocalWorkDir()
node(nodeLabel()) {
timeout(time: 60, unit: 'MINUTES') {
ansiColor('xterm') {
timestamps {
def buildFailed = false
try {
stage('Clean Workspace') {
pipelineHelpers.cleanupWorkspace()
}
stage('Checkout Code') {
sh 'rm -vrf ./tmp'
checkout scm
distribution.stashBuildScripts()
}
stage('Setup') {
cleanAndSetup()
setupStage()
}
stage('Build Docker Image') {
def stageStartTime = System.currentTimeMillis()
try {
buildDockerImageStage.patchsetImage()
} finally {
buildSummaryReport.trackStage('Build Docker Image', stageStartTime)
}
}
stage('Run Migrations') {
def stageStartTime = System.currentTimeMillis()
try {
runMigrationsStage()
} finally {
buildSummaryReport.trackStage('Run Migrations', stageStartTime)
}
}
stage('Run Tests') {
def rspecqStages = [:]
stage('Setup Docker Images') {
rspecStage.setupNode()
}
rspecqStages['Reporter'] = {
try {
sh(script: "docker run -e SENTRY_DSN -e RSPECQ_REDIS_URL -t $env.PATCHSET_TAG bundle exec rspecq \
--build=${env.JOB_NAME}_build${env.BUILD_NUMBER} \
--queue-wait-timeout 120 \
--redis-url $env.RSPECQ_REDIS_URL \
--report", label: 'Reporter')
} catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
if (e.causes[0] instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) {
sh '''#!/bin/bash
ids=($(docker ps -aq --filter "name=canvas-"))
for i in "${ids[@]}"
do
docker exec $i bash -c "cat /usr/src/app/log/cmd_output/*.log"
done
'''
}
throw e
}
}
// RSpecQ Set 00 runs on main coordinator node
rspecqStages['RSpecQ 00'] = {
withEnv([
"CI_NODE_INDEX=00",
"BUILD_NAME=${env.JOB_NAME}_build${env.BUILD_NUMBER}",
"CRYSTALBALL_MAP=1"
]) {
def stageName = 'RSpecQ 00'
def stageStartTime = System.currentTimeMillis()
try {
stage('00 Run Tests') {
catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') {
rspecStage.runRspecqSuite()
}
}
stage('00 Collect Results') {
rspecStage.tearDownNode()
}
} finally {
buildSummaryReport.trackStage('RSpecQ Set 00', stageStartTime)
}
}
}
// Remaining nodes (1 through rspecqNodeTotal-1)
for (int i = 1; i < rspecqNodeTotal; i++) {
def indexStr = String.format('%02d', i)
rspecqStages["RSpecQ ${indexStr}"] = {
rspecStage.runRspecQWorkerNode(indexStr, ["CRYSTALBALL_MAP=1"])
}
}
parallel(rspecqStages)
}
} catch (e) {
// currentBuild.currentResult is not updated until after the finally
// block completes, so it reads SUCCESS even on failure. Capture the
// failure here so the finally block can report the correct status.
buildFailed = true
throw e
} finally {
def buildResult = buildFailed ? 'FAILURE' : currentBuild.currentResult
pipelineHelpers.cleanupDocker()
collectCrystalballMap()
buildSummaryReport.addFailureRun('Main Build', currentBuild)
if (buildFailed || currentBuild.currentResult != 'SUCCESS') {
sendCrystalballSlack(buildFailed ? 'FAILURE' : currentBuild.currentResult)
}
buildSummaryReport.publishReport('Build Summary Report', buildResult)
buildSummaryReport.saveRunManifest()
}
}
}
}
}