-
Notifications
You must be signed in to change notification settings - Fork 96
/
Jenkinsfile
336 lines (322 loc) · 16.5 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#!groovy
// trick from https://github.com/jenkinsci/workflow-cps-global-lib-plugin/pull/43
def lib = library identifier: 'sct@snapshot', retriever: legacySCM(scm)
def target_backends = ['aws', 'gce', 'docker', 'k8s-local-kind-aws', 'k8s-eks', 'azure']
def sct_runner_backends = ['aws', 'gce', 'docker', 'k8s-local-kind-aws', 'k8s-eks', 'azure']
def createRunConfiguration(String backend) {
def configuration = [
backend: backend,
test_name: 'longevity_test.LongevityTest.test_custom_time',
test_config: 'test-cases/PR-provision-test.yaml',
availability_zone: 'a',
scylla_version: params.scylla_version,
region: 'eu-west-1',
]
if (backend == 'gce') {
configuration.gce_datacenter = "us-east1"
} else if (backend == 'azure') {
configuration.azure_region_name = 'eastus'
configuration.availability_zone = ''
} else if (backend == 'docker') {
configuration.test_config = "test-cases/PR-provision-test-docker.yaml"
} else if (backend in ['k8s-local-kind-aws', 'k8s-eks']) {
if (params.scylla_version.endsWith('latest')) {
configuration.scylla_version = 'latest'
configuration.k8s_scylla_operator_helm_repo = 'https://storage.googleapis.com/scylla-operator-charts/latest'
configuration.k8s_scylla_operator_chart_version = 'latest'
configuration.k8s_enable_tls = 'false'
configuration.k8s_enable_sni = 'false'
}
configuration.test_config = "test-cases/scylla-operator/functional.yaml"
configuration.test_name = "functional_tests/scylla_operator"
configuration.functional_tests = true
configuration.availability_zone = 'a,b'
}
return configuration
}
def runSendEmail(){
sh """#!/bin/bash
set -xe
env
export LAST_COMMIT=`git rev-parse HEAD`
export RECIPIENTS=`git show -s --format='%ae' \$LAST_COMMIT`,`git show -s --format='%ce' \$LAST_COMMIT`
echo "Start send email ..."
./docker/env/hydra.sh send-email --logdir "`pwd`" --email-recipients "\${RECIPIENTS}"
echo "Email sent"
"""
}
def runRestoreMonitoringStack(){
sh """#!/bin/bash
set -xe
env
echo "Restoring Monitor stack for test-id \$SCT_TEST_ID"
./docker/env/hydra.sh investigate show-monitor \$SCT_TEST_ID --kill true
"""
}
pipeline {
agent {
label {
label "aws-sct-builders-eu-west-1-v3-CI"
}
}
parameters {
string(defaultValue: "5.2.11",
description: 'the scylla version to use for the provision tests',
name: 'scylla_version')
string(defaultValue: '',
description: 'Actual user requesting job start, for automated job builds (e.g. through Argus)',
name: 'requested_by_user')
}
environment {
AWS_ACCESS_KEY_ID = credentials('qa-aws-secret-key-id')
AWS_SECRET_ACCESS_KEY = credentials('qa-aws-secret-access-key')
}
options {
timestamps()
buildDiscarder(logRotator(numToKeepStr: '10'))
}
stages {
stage("precommit") {
options {
timeout(time: 15, unit: 'MINUTES')
}
steps {
script {
dockerLogin(params)
try {
sh './docker/env/hydra.sh pre-commit'
// also check the commit-messge for the rules we want
pullRequestSetResult('success', 'jenkins/precommit', 'Precommit passed')
} catch(Exception ex) {
pullRequestSetResult('failure', 'jenkins/precommit', 'Precommit failed')
}
}
}
}
stage("unittest") {
options {
timeout(time: 20, unit: 'MINUTES')
}
steps {
script {
try {
checkoutQaInternal(params)
sh './docker/env/hydra.sh unit-tests'
pullRequestSetResult('success', 'jenkins/unittests', 'All unit tests are passed')
} catch(Exception ex) {
pullRequestSetResult('failure', 'jenkins/unittests', 'Some unit tests failed')
}
}
}
}
stage("lint test-cases") {
options {
timeout(time: 10, unit: 'MINUTES')
}
steps {
script {
try {
checkoutQaInternal(params)
sh ''' ./docker/env/hydra.sh bash ./utils/lint_test_cases.sh '''
pullRequestSetResult('success', 'jenkins/lint_test_cases', 'All test cases are passed')
} catch(Exception ex) {
pullRequestSetResult('failure', 'jenkins/lint_test_cases', 'Some test cases failed')
}
}
}
}
stage("run mocked tests") {
options {
timeout(time: 10, unit: 'MINUTES')
}
steps {
script {
try {
sh ''' ./docker/env/hydra.sh run-aws-mock -r us-east-1 '''
sleep 10 // seconds
sh ''' ./docker/env/hydra.sh --aws-mock run-pytest functional_tests/mocked '''
pullRequestSetResult('success', 'jenkins/mocked_tests', 'All mocked tests are passed')
} catch(Exception ex) {
pullRequestSetResult('failure', 'jenkins/mocked_tests', 'Some mocked tests failed')
}
sh ''' ./docker/env/hydra.sh clean-aws-mocks '''
}
}
}
stage("integration tests") {
when {
expression {
return pullRequestContainsLabels("test-integration")
}
}
options {
timeout(time: 40, unit: 'MINUTES')
}
steps {
script {
def curr_params = createRunConfiguration('docker')
def builder = getJenkinsLabels(curr_params.backend, curr_params.region, curr_params.gce_datacenter, curr_params.azure_region_name)
try {
withEnv(["SCT_TEST_ID=${UUID.randomUUID().toString()}",]) {
dir('scylla-cluster-tests') {
checkout scm
dockerLogin(params)
wrap([$class: 'BuildUser']) {
echo "calling createSctRunner"
timeout(time: 5, unit: 'MINUTES') {
createSctRunner(curr_params, 50 , builder.region)
}
}
sh """#!/bin/bash
set -xe
echo "start integration-tests ..."
RUNNER_IP=\$(cat sct_runner_ip||echo "")
./docker/env/hydra.sh --execute-on-runner \${RUNNER_IP} integration-tests
echo "end integration-tests ..."
"""
}
pullRequestSetResult('success', 'jenkins/integration-tests', 'All integration tests are passed')
}
} catch(Exception ex) {
pullRequestSetResult('failure', 'jenkins/integration-tests', 'Some integration tests failed')
}
}
}
}
stage("provision test") {
when {
expression {
def labels = [
"test-provision",
"test-provision-docker",
"test-provision-aws", "test-provision-aws-reuse",
"test-provision-gce", "test-provision-gce-reuse",
"test-provision-azure", "test-provision-azure-reuse",
"test-provision-k8s-local-kind-aws", "test-provision-k8s-local-kind-aws-reuse",
"test-provision-k8s-eks", "test-provision-k8s-eks-reuse"
].join(",")
return pullRequestContainsLabels(labels)
}
}
steps {
script {
def sctParallelTests = [:]
target_backends.each {
def backend = it
if (pullRequestContainsLabels("test-provision,test-provision-${backend},test-provision-${backend}-reuse")) {
sctParallelTests["provision test on ${backend}"] = {
def curr_params = createRunConfiguration(backend)
def working_dir = "${backend}/scylla-cluster-tests"
def builder = getJenkinsLabels(curr_params.backend, curr_params.region, curr_params.gce_datacenter, curr_params.azure_region_name)
withEnv(["SCT_TEST_ID=${UUID.randomUUID().toString()}",]) {
script {
def result = null
dir(working_dir) {
checkout scm
}
dockerLogin(params)
if (sct_runner_backends.contains(backend)){
try {
wrap([$class: 'BuildUser']) {
dir(working_dir) {
timeout(time: 5, unit: 'MINUTES') {
echo "calling createSctRunner"
createSctRunner(curr_params, 90 , builder.region)
}
}
}
} catch(Exception err) {
echo "${err}"
result = 'FAILURE'
pullRequestSetResult('failure', "jenkins/provision_${backend}", 'Some test cases are failed')
}
}
try {
wrap([$class: 'BuildUser']) {
env.BUILD_USER_ID=env.CHANGE_AUTHOR
timeout(time: 300, unit: 'MINUTES') {
dir(working_dir) {
echo "Run provision test"
runSctTest(curr_params, builder.region, curr_params.get('functional_tests', false))
result = 'SUCCESS'
pullRequestSetResult('success', "jenkins/provision_${backend}", 'All test cases are passed')
}
}
}
} catch(Exception err) {
echo "${err}"
result = 'FAILURE'
pullRequestSetResult('failure', "jenkins/provision_${backend}", 'Some test cases are failed')
}
try {
wrap([$class: 'BuildUser']) {
timeout(time: 90, unit: 'MINUTES') {
dir(working_dir) {
runCollectLogs(curr_params, builder.region)
}
}
}
} catch(Exception err) {
echo "${err}"
}
if (!(backend in ['k8s-local-kind-aws', 'k8s-eks'])) {
try {
wrap([$class: 'BuildUser']) {
timeout(time: 25, unit: 'MINUTES') {
dir(working_dir) {
runRestoreMonitoringStack()
}
}
}
} catch(Exception err) {
echo "${err}"
currentBuild.result = 'FAILURE'
}
}
if (pullRequestContainsLabels("test-provision-${backend}-reuse")) {
try {
withEnv(["SCT_REUSE_CLUSTER=${env.SCT_TEST_ID}"]) {
wrap([$class: 'BuildUser']) {
env.BUILD_USER_ID=env.CHANGE_AUTHOR
timeout(time: 300, unit: 'MINUTES') {
dir(working_dir) {
echo "Reuse the cluster and re-run provision test"
runSctTest(curr_params, builder.region, curr_params.get('functional_tests', false))
result = 'SUCCESS'
pullRequestSetResult('success', "jenkins/provision_${backend}", 'All test cases are passed')
}
}
}
}
} catch(Exception err) {
echo "${err}"
result = 'FAILURE'
pullRequestSetResult('failure', "jenkins/provision_${backend}", 'Some test cases are failed during cluster reuse test')
}
}
try {
wrap([$class: 'BuildUser']) {
timeout(time: 30, unit: 'MINUTES') {
dir(working_dir) {
runCleanupResource(curr_params, builder.region)
}
}
}
} catch(Exception err) {
echo "${err}"
}
if (result == 'FAILURE'){
currentBuild.result = 'FAILURE'
sh "exit 1"
}
}
}
}
}
}
parallel sctParallelTests
}
}
}
}
}