forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.js
146 lines (129 loc) · 4.49 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
#!/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"
def COFFEE_NODE_COUNT = 2
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() {
try {
archiveArtifacts artifacts: 'tmp/**/*.xml'
junit "tmp/**/*.xml"
sh 'find ./tmp -path "*.xml"'
} finally {
execute 'bash/docker-cleanup.sh --allow-failure'
}
}
pipeline {
agent none
options { ansiColor('xterm') }
environment {
COMPOSE_FILE = 'docker-compose.new-jenkins.canvas.yml:docker-compose.new-jenkins-karma.yml'
FORCE_FAILURE = configuration.forceFailureJS()
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: 10) {
sh 'rm -vrf ./tmp/*'
checkout scm
sh './build/new-jenkins/docker-with-flakey-network-protection.sh pull $PATCHSET_TAG'
sh 'docker-compose build'
}
}
stage('Run Tests') {
timeout(time: 60) {
script {
def tests = [:]
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}")
}
}
}
}
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}")
}
}
}
tests['canvas_quizzes'] = {
sh 'build/new-jenkins/js/tests-quizzes.sh'
}
for(int i = 0; i < COFFEE_NODE_COUNT; i++) {
tests["Karma - Spec Group - coffee${i}"] = makeKarmaStage('coffee', i, COFFEE_NODE_COUNT)
}
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)
}
}
}
}
}
}
}
}
}