forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.js
186 lines (166 loc) · 5.38 KB
/
Jenkinsfile.js
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
#!/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 isForceFailure() {
def flags = load 'build/new-jenkins/groovy/commit-flags.groovy'
return flags.isForceFailure() ? "1" : ''
}
def getImageTagVersion() {
def flags = load 'build/new-jenkins/groovy/commit-flags.groovy'
// total hack, we shouldnt do it like this. but until there is a better
// way of passing info across builds, this is path of least resistance..
// also, it didnt seem to work with multiple return statements, so i'll
// just go ahead and leave this monstrosity here.
return env.RUN_COVERAGE == '1' ? 'master' : flags.getImageTagVersion()
}
def copyFiles(docker_name, docker_dir, host_dir) {
sh "mkdir -vp ./$host_dir"
sh "docker cp \$(docker ps -qa -f name=$docker_name):/usr/src/app/$docker_dir ./$host_dir"
}
def withSentry(block) {
def credentials = load 'build/new-jenkins/groovy/credentials.groovy'
credentials.withSentryCredentials(block)
}
def runInSeriesOrParallel(is_series, stages_map) {
if (is_series) {
echo "running tests in series: ${stages_map.keys}"
stages_map.each { name, block ->
stage(name) {
block()
}
}
}
else {
echo "running tests in parallel: ${stages_map.keys}"
parallel(stages_map)
}
}
pipeline {
agent { label 'canvas-docker' }
options { ansiColor('xterm') }
environment {
COMPOSE_FILE = 'docker-compose.new-jenkins-web.yml:docker-compose.new-jenkins-karma.yml'
COVERAGE = runCoverage()
FORCE_FAILURE = isForceFailure()
SENTRY_URL="https://sentry.insops.net"
SENTRY_ORG="instructure"
SENTRY_PROJECT="master-javascript-build"
}
stages {
stage('Pre-Cleanup') {
steps {
timeout(time: 2) {
sh 'build/new-jenkins/docker-cleanup.sh'
sh 'build/new-jenkins/print-env-excluding-secrets.sh'
sh 'rm -vrf ./tmp/*'
}
}
}
stage('Tests Setup') {
steps {
timeout(time: 60) {
sh 'build/new-jenkins/docker-compose-pull.sh'
sh 'docker-compose build'
}
}
}
stage('Test Stage Coordinator') {
steps {
script {
def tests = [:]
tests['Jest'] = {
withEnv(['CONTAINER_NAME=tests-jest']) {
try {
withSentry {
sh 'build/new-jenkins/js/tests-jest.sh'
}
if (env.COVERAGE == '1') {
copyFiles(env.CONTAINER_NAME, 'coverage-jest', "./tmp/${env.CONTAINER_NAME}-coverage")
}
}
finally {
copyFiles(env.CONTAINER_NAME, 'coverage-js', "./tmp/${env.CONTAINER_NAME}")
}
}
}
tests['Packages'] = {
withEnv(['CONTAINER_NAME=tests-packages']) {
try {
withSentry {
sh 'build/new-jenkins/js/tests-packages.sh'
}
}
finally {
copyFiles(env.CONTAINER_NAME, 'packages', "./tmp/${env.CONTAINER_NAME}")
}
}
}
tests['canvas_quizzes'] = {
sh 'build/new-jenkins/js/tests-quizzes.sh'
}
['coffee', 'jsa', 'jsg', 'jsh'].each { group ->
tests["Karma - Spec Group - ${group}"] = {
withEnv(["CONTAINER_NAME=tests-karma-${group}", "JSPEC_GROUP=${group}"]) {
try {
withSentry {
sh 'build/new-jenkins/js/tests-karma.sh'
}
if (env.COVERAGE == '1') {
copyFiles(env.CONTAINER_NAME, 'coverage-karma', "./tmp/${env.CONTAINER_NAME}-coverage")
}
}
finally {
copyFiles(env.CONTAINER_NAME, 'coverage-js', "./tmp/${env.CONTAINER_NAME}")
}
}
}
}
runInSeriesOrParallel(env.COVERAGE == '1', tests)
}
}
}
stage('Upload Coverage') {
when { expression { env.COVERAGE == '1' } }
steps {
timeout(time: 10) {
sh 'build/new-jenkins/js/coverage-report.sh'
archiveArtifacts(artifacts: 'coverage-report-js/**/*')
uploadCoverage([
uploadSource: "/coverage-report-js/report-html",
uploadDest: "canvas-lms-js/coverage"
])
}
}
}
}
post {
always {
script {
junit allowEmptyResults: true, testResults: 'tmp/**/*.xml'
sh 'find ./tmp -path "*.xml"'
}
}
cleanup {
sh 'build/new-jenkins/docker-cleanup.sh --allow-failure'
}
}
}