-
Notifications
You must be signed in to change notification settings - Fork 35
/
Jenkinsfile.offers-infrastructure-tests
146 lines (114 loc) · 5.25 KB
/
Jenkinsfile.offers-infrastructure-tests
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
#!/bin/env groovy
import groovy.time.*
@Library('[email protected]') _
properties([
[$class: 'JobRestrictionProperty'],
parameters([
string(name: 'DOCKER_REGISTRY_URL', defaultValue: '141047255820.dkr.ecr.us-east-1.amazonaws.com'),
]),
])
def CONFIG = 'configs/ci/offers-infrastructure-tests.js'
def TEST_PARAMS = "-l firefox-web-ext --grep 'send fake signals to backend through hpn' --firefox ~/firefoxNightly/firefox/firefox"
String currentCommitHash
String codeDockerImage
node('docker && !gpu && us-east-1') {
stage('checkout') {
def scmInfo = checkout scm
currentCommitHash = scmInfo.GIT_COMMIT
codeDockerImage = "navigation-extension/tests:${currentCommitHash}-offers-infra-test"
}
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()
// add date to the tag in order to download FF beta and nightly at least once per day and stay up-to-date
def today = new Date().format('yyyyMMdd')
def dockerTag = "${dockerfileChecksum}-${packageJsonChecksum}-${today}-offers-infra-test"
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}
COPY --chown=node:node . /app/
"""
def codeImage = docker.build(
codeDockerImage,
'-f Dockerfile.code .'
)
codeImage.push "${currentCommitHash}-offers-infra-test"
}
}
}
node('docker && gpu && us-east-1') {
def HOST = helpers.getIp()
def VNC_PORT = helpers.getFreePort(lower: 20000, upper: 20999)
def dockerParams = "-p ${VNC_PORT}:5900 --add-host cliqztest.com:127.0.0.1 --device /dev/nvidia0 --device /dev/nvidiactl --cpus=2"
docker.withRegistry("https://${params.DOCKER_REGISTRY_URL}") {
def image = docker.image(codeDockerImage)
stage('tests: get image') {
image.pull()
}
withEnv(["CLIQZ_CONFIG_PATH=${CONFIG}"]) {
docker.image(image.imageName()).inside(dockerParams) {
timeout(25) {
stage('tests: run') {
def report
def hasErrors
try {
def timeBefore = new Date()
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 ${TEST_PARAMS} --environment development --ci report.xml > /dev/null; true
cp report.xml ${env.WORKSPACE}
cat report.xml
"""
def timeAfter = new Date()
def duration = "${TimeCategory.minus(timeAfter, timeBefore).getHours()}h, ${TimeCategory.minus(timeAfter, timeBefore).getMinutes()}m"
Map r = xunit.parse('/app/report.xml')
if (!r.containsKey('errors')) {
r.errors = '0'
}
report = "tests: ${r.tests}, f/e: ${r.failures}/${r.errors}, time: ${duration}"
print report
hasErrors = (r.failures != '0') || (r.errors != '0')
if (r.tests == '0') {
throw new Exception('No tests have been run!')
}
junit(
allowEmptyResults: true,
healthScaleFactor: 0.0,
testResults: 'report.xml'
)
} catch (e) {
report = e
hasErrors = true
}
if (hasErrors) {
currentBuild.result = "FAILURE"
}
} // end stage
} // end timeout
} // end docker
}
}
}