/
Jenkinsfile
236 lines (199 loc) · 7.83 KB
/
Jenkinsfile
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
#!/bin/env groovy
@Library('cliqz-shared-library@v1.2') _
if (job.hasNewerQueuedJobs()) {
error('Has Jobs in queue, aborting')
}
properties([
[$class: 'JobRestrictionProperty'],
disableConcurrentBuilds(),
parameters([
string(name: 'DOCKER_REGISTRY_URL', defaultValue: '141047255820.dkr.ecr.us-east-1.amazonaws.com'),
string(name: 'AWS_REGION', defaultValue: 'us-east-1'),
]),
])
def matrix = [
'unit tests': [
'gpu': false,
'testParams': 'configs/unit-tests.json -l unit-node',
],
'browser: content': [
'gpu': true,
'testParams': 'configs/browser.js -l chromium',
],
'mobile: content': [
'gpu': true,
'testParams': 'configs/mobile.json -l chromium',
],
'firefox 52': [
'gpu': true,
'testParams': 'configs/jenkins.js -l firefox-web-ext --firefox ~/firefox52/firefox/firefox',
],
'firefox 56': [
'gpu': true,
'testParams': 'configs/jenkins.js -l firefox-web-ext --firefox ~/firefox56/firefox/firefox',
],
'funnelcake 56': [
'gpu': true,
'testParams': 'configs/jenkins-funnelcake.js -l firefox-web-ext --firefox ~/firefox56/firefox/firefox',
],
'firefox stresstest (52)': [
'gpu': true,
'testParams': 'configs/jenkins.js -l firefox-web-ext-stresstest --firefox ~/firefox52/firefox/firefox',
],
'chromium': [
'gpu': true,
'testParams': 'configs/cliqzium.json -l chromium-selenium',
],
]
String triggeringCommitHash = github.getCommitHash()
String currentCommitHash
String codeDockerImage
def setGithubCommitStatus(commit, context, status, message) {
withCredentials([[
$class: 'StringBinding',
credentialsId: '5d3e0a3c-2490-491b-8a67-aa5eab2f27f2',
variable: 'GITHUB_TOKEN'
]]) {
github.setCommitStatus(
env.GITHUB_TOKEN,
'cliqz/navigation-extension',
commit,
context,
status,
message
)
}
}
parallel helpers.entries(matrix).collectEntries {
[(it[0]): {
setGithubCommitStatus(triggeringCommitHash, it[0], 'pending', 'pending')
}]
}
node('docker && !gpu && us-east-1') {
stage('checkout') {
def scmInfo = checkout scm
currentCommitHash = scmInfo.GIT_COMMIT
codeDockerImage = "navigation-extension/tests:${currentCommitHash}"
}
def dockerfileChecksum = sh(returnStdout: true, script: 'md5sum Dockerfile.ci | cut -d" " -f1').trim()
def packageJsonChecksum = sh(returnStdout: true, script: 'md5sum package.json | cut -d" " -f1').trim()
def bowerJsonChecksum = sh(returnStdout: true, script: 'md5sum bower.json | cut -d" " -f1').trim()
def dockerTag = "${dockerfileChecksum}-${packageJsonChecksum}-${bowerJsonChecksum}"
// authorize docker deamon to access registry
sh "`aws ecr get-login --no-include-email --region=${params.AWS_REGION}`"
docker.withRegistry("https://${params.DOCKER_REGISTRY_URL}") {
stage('prepare docker base image') {
ansiColor('xterm') {
def baseImageName = "navigation-extension/build:${dockerTag}"
try {
def image = docker.image(baseImageName)
image.pull()
} catch (e) {
print e
def baseImage = docker.build(
baseImageName,
'-f Dockerfile.ci .'
)
baseImage.push dockerTag
}
}
}
stage('prepare docker code image') {
writeFile file: 'Dockerfile.code', text: """
FROM ${params.DOCKER_REGISTRY_URL}/navigation-extension/build:${dockerTag}
ADD . /app/
"""
def codeImage = docker.build(
codeDockerImage,
'-f Dockerfile.code .'
)
codeImage.push currentCommitHash
}
}
}
def test(Map m) {
def context = m.context
def testParams = m.testParams
def gpu = m.gpu
def getCodeDockerImage = m.getCodeDockerImage
def getTriggeringCommitHash = m.getTriggeringCommitHash
def nodeLabels = gpu ? 'us-east-1 && docker && gpu' : 'us-east-1 && docker && !gpu'
return {
node(nodeLabels) {
def codeDockerImage = getCodeDockerImage()
def triggeringCommitHash = getTriggeringCommitHash()
def HOST = helpers.getIp()
def VNC_PORT = helpers.getFreePort(lower: 20000, upper: 20999)
def dockerParams = "-p ${VNC_PORT}:5900"
if (gpu) {
dockerParams += ' --device /dev/nvidia0 --device /dev/nvidiactl --cpus=2'
}
// authorize docker deamon to access registry
sh "`aws ecr get-login --no-include-email --region=${params.AWS_REGION}`"
docker.withRegistry("https://${params.DOCKER_REGISTRY_URL}") {
def image = docker.image(codeDockerImage)
stage('tests: get image') {
image.pull()
}
docker.image(image.imageName()).inside(dockerParams) {
setGithubCommitStatus(
triggeringCommitHash,
context,
'pending',
"VNC ${HOST}:${VNC_PORT}"
)
timeout(35) {
stage('tests: run') {
def report
def hasErrors
try {
sh """#!/bin/bash
set -x
cd /app
rm -f report.xml
export DISPLAY=:0
Xvfb \$DISPLAY -screen 0 1024x768x24 -ac &
openbox&
x11vnc -storepasswd vnc /tmp/vncpass
x11vnc -rfbport 5900 -rfbauth /tmp/vncpass -forever > /dev/null 2>&1 &
./fern.js test ${testParams} --environment testing --ci report.xml > /dev/null; true
cp report.xml ${env.WORKSPACE}
"""
Map r = xunit.parse('/app/report.xml')
if (!r.containsKey('errors')) {
r.errors = '0'
}
report = "tests: ${r.tests}, failures: ${r.failures}, errors: ${r.errors}"
hasErrors = (r.failures != '0') || (r.errors != '0')
junit(
allowEmptyResults: true,
healthScaleFactor: 0.0,
testResults: 'report.xml'
)
} catch (e) {
report = e
hasErrors = true
}
setGithubCommitStatus(
triggeringCommitHash,
context,
hasErrors ? 'failure' : 'success',
report
)
} // end stage
} // end timeout
} // end docker
}
}
}
}
def stepsForParallel = helpers.entries(matrix).collectEntries {
[(it[0]): test(
context: it[0],
testParams: it[1]['testParams'],
gpu: it[1]['gpu'],
getCodeDockerImage: { codeDockerImage },
getTriggeringCommitHash: { triggeringCommitHash }
)]
}
parallel stepsForParallel