forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.js
158 lines (142 loc) · 4.89 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
#!/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/>.
*/
library "canvas-builds-library@${env.CANVAS_BUILDS_REFSPEC}"
def COFFEE_NODE_COUNT = 4
def DEFAULT_NODE_COUNT = 1
def JSG_NODE_COUNT = 3
def copyFiles(dockerName, dockerPath, hostPath) {
sh "mkdir -vp ./$hostPath"
sh "docker cp \$(docker ps -qa -f name=$dockerName):/usr/src/app/$dockerPath ./$hostPath"
}
def makeKarmaStage(group, ciNode, ciTotal) {
return {
withEnv([
"CI_NODE_INDEX=${ciNode}",
"CI_NODE_TOTAL=${ciTotal}",
"CONTAINER_NAME=tests-karma-${group}-${ciNode}",
"JSPEC_GROUP=${group}"
]) {
try {
credentials.withSentryCredentials {
sh 'build/new-jenkins/js/tests-karma.sh'
}
} finally {
copyFiles(env.CONTAINER_NAME, 'coverage-js', "./tmp/${env.CONTAINER_NAME}")
}
}
}
}
def cleanupFn() {
timeout(time: 2) {
try {
if(env.TEST_SUITE != 'upload') {
archiveArtifacts artifacts: 'tmp/**/*.xml'
junit "tmp/**/*.xml"
sh 'find ./tmp -path "*.xml"'
}
} finally {
libraryScript.execute 'bash/docker-cleanup.sh --allow-failure'
}
}
}
pipeline {
agent none
options {
ansiColor('xterm')
timeout(time: 20)
timestamps()
}
environment {
COMPOSE_DOCKER_CLI_BUILD=1
COMPOSE_FILE = 'docker-compose.new-jenkins-js.yml'
DOCKER_BUILDKIT=1
FORCE_FAILURE = configuration.forceFailureJS()
PROGRESS_NO_TRUNC=1
SENTRY_URL="https://sentry.insops.net"
SENTRY_ORG="instructure"
SENTRY_PROJECT="master-javascript-build"
}
stages {
stage('Environment') {
steps {
script {
protectedNode('canvas-docker', { cleanupFn() }) {
stage('Setup') {
cleanAndSetup()
timeout(time: 3) {
sh 'rm -vrf ./tmp/*'
def refspecToCheckout = env.GERRIT_PROJECT == "canvas-lms" ? env.JENKINSFILE_REFSPEC : env.CANVAS_LMS_REFSPEC
checkoutRepo("canvas-lms", refspecToCheckout, 1)
sh 'docker-compose build'
}
}
stage('Run Tests') {
timeout(time: 10) {
script {
def tests = [:]
if(env.TEST_SUITE == 'upload') {
sh """
docker tag local/js-runner $JS_DEBUG_IMAGE_TAG
docker push $JS_DEBUG_IMAGE_TAG
"""
} else if(env.TEST_SUITE == 'jest') {
tests['Jest'] = {
withEnv(['CONTAINER_NAME=tests-jest']) {
try {
credentials.withSentryCredentials {
sh 'build/new-jenkins/js/tests-jest.sh'
}
} finally {
copyFiles(env.CONTAINER_NAME, 'coverage-js', "./tmp/${env.CONTAINER_NAME}")
}
}
}
} else if(env.TEST_SUITE == 'coffee') {
for(int i = 0; i < COFFEE_NODE_COUNT; i++) {
tests["Karma - Spec Group - coffee${i}"] = makeKarmaStage('coffee', i, COFFEE_NODE_COUNT)
}
} else if(env.TEST_SUITE == 'karma') {
tests['Packages'] = {
withEnv(['CONTAINER_NAME=tests-packages']) {
try {
credentials.withSentryCredentials {
sh 'build/new-jenkins/js/tests-packages.sh'
}
} finally {
copyFiles(env.CONTAINER_NAME, 'packages', "./tmp/${env.CONTAINER_NAME}")
}
}
}
for(int i = 0; i < JSG_NODE_COUNT; i++) {
tests["Karma - Spec Group - jsg${i}"] = makeKarmaStage('jsg', i, JSG_NODE_COUNT)
}
['jsa', 'jsh'].each { group ->
tests["Karma - Spec Group - ${group}"] = makeKarmaStage(group, 0, DEFAULT_NODE_COUNT)
}
}
parallel(tests)
}
}
}
}
}
}
}
}
}