-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile
362 lines (356 loc) · 12.1 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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
#!groovy
// See 'Loading libraries dynamically' here: https://jenkins.io/doc/book/pipeline/shared-libraries/
library 'cdis-jenkins-lib@master'
import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
node {
def AVAILABLE_NAMESPACES = ciEnsPoolHelper.fetchCIEnvs()
List<String> namespaces = []
List<String> listOfSelectedTests = []
skipUnitTests = false
skipQuayImgBuildWait = false
doNotRunTests = false
kubectlNamespace = null
kubeLocks = []
testedEnv = "" // for manifest pipeline
pipeConfig = pipelineHelper.setupConfig([:])
pipelineHelper.cancelPreviousRunningBuilds()
prLabels = githubHelper.fetchLabels()
try {
stage('CleanWorkspace') {
cleanWs()
}
stage('FetchCode'){
gitHelper.fetchAllRepos(pipeConfig['currentRepoName'])
}
stage('CheckPRLabels') {
try {
// giving a chance for auto-label gh actions to catch up
// sleep(10)
for(label in prLabels) {
println(label['name']);
switch(label['name']) {
case ~/^test-.*/:
println('Select a specific test suite and feature')
selectedTestLabel = label['name'].split("-")
println "selected test: suites/" + selectedTestLabel[1] + "/" + selectedTestLabel[2] + ".js"
selectedTest = "suites/" + selectedTestLabel[1] + "/" + selectedTestLabel[2] + ".js"
listOfSelectedTests.add(selectedTest)
break
case "skip-gen3-helper-tests":
println('Skipping unit tests assuming they have been verified in a previous PR check iteration...')
skipUnitTests = true
break
case "skip-awshelper-build-wait":
println('Skipping the WaitForQuayBuild stage as it is not necessary for every PR...')
skipQuayImgBuildWait = true
break
case "doc-only":
println('Skip tests if git diff matches expected criteria')
doNotRunTests = docOnlyHelper.checkTestSkippingCriteria()
skipUnitTests = true
skipQuayImgBuildWait = true
break
case "debug":
println("Call npm test with --debug")
println("leverage CodecepJS feature require('codeceptjs').output.debug feature")
break
case "not-ready-for-ci":
currentBuild.result = 'ABORTED'
error('This PR is not ready for CI yet, aborting...')
break
case AVAILABLE_NAMESPACES:
println('found this namespace label! ' + label['name']);
namespaces.add(label['name'])
break
case "qaplanetv2":
println('This PR check will run in a qaplanetv2 environment! ');
namespaces.add('ci-env-1')
break
default:
println('no-effect label')
break
}
}
// If none of the jenkins envs. have been selected pick one at random
if (namespaces.isEmpty()) {
println('populating namespaces with list of available namespaces...')
namespaces = AVAILABLE_NAMESPACES
}
// If a specific test suite is not specified, run them all
if (listOfSelectedTests.isEmpty()) {
listOfSelectedTests.add("all")
}
} catch (ex) {
metricsHelper.writeMetricWithResult(STAGE_NAME, false)
throw ex
}
metricsHelper.writeMetricWithResult(STAGE_NAME, true)
}
stage('gen3 helper test suite') {
try {
println("namespaces: ${namespaces}")
if(!skipUnitTests) {
sh 'GEN3_HOME=$WORKSPACE/cloud-automation XDG_DATA_HOME=$WORKSPACE/dataHome bash cloud-automation/gen3/bin/testsuite.sh --profile jenkins'
} else {
Utils.markStageSkippedForConditional(STAGE_NAME)
}
} catch (ex) {
metricsHelper.writeMetricWithResult(STAGE_NAME, false)
throw ex
}
metricsHelper.writeMetricWithResult(STAGE_NAME, true)
}
stage('gen3 helper test suite with zsh') {
try {
if(!skipUnitTests) {
sh 'GEN3_HOME=$WORKSPACE/cloud-automation XDG_DATA_HOME=$WORKSPACE/dataHome zsh cloud-automation/gen3/bin/testsuite.sh --profile jenkins'
} else {
Utils.markStageSkippedForConditional(STAGE_NAME)
}
} catch (ex) {
metricsHelper.writeMetricWithResult(STAGE_NAME, false)
throw ex
}
metricsHelper.writeMetricWithResult(STAGE_NAME, true)
}
stage('pytest') {
try {
if(!skipUnitTests) {
sh 'pip3 install boto3 --upgrade'
sh 'pip3 install kubernetes --upgrade'
sh 'python3 -m pytest cloud-automation/apis_configs/'
sh 'python3 -m pytest cloud-automation/gen3/lib/dcf/'
sh 'cd cloud-automation/tf_files/aws/modules/common-logging && python3 -m pytest testLambda.py'
sh 'cd cloud-automation/files/lambda && python3 -m pytest test-security_alerts.py'
sh 'cd cloud-automation/kube/services/jupyterhub && python3 -m pytest test-jupyterhub_config.py'
sh 'bash cloud-automation/files/scripts/es-secgroup-sync.sh test'
} else {
Utils.markStageSkippedForConditional(STAGE_NAME)
}
} catch (ex) {
metricsHelper.writeMetricWithResult(STAGE_NAME, false)
throw ex
}
metricsHelper.writeMetricWithResult(STAGE_NAME, true)
}
stage('nginx helper test suite') {
try {
if(!skipUnitTests) {
dir('cloud-automation/kube/services/revproxy') {
sh 'npx jasmine helpersTest.js'
}
} else {
Utils.markStageSkippedForConditional(STAGE_NAME)
}
} catch (ex) {
metricsHelper.writeMetricWithResult(STAGE_NAME, false)
throw ex
}
metricsHelper.writeMetricWithResult(STAGE_NAME, true)
}
stage('python 2 base image dockerrun.sh test') {
try {
if(!skipUnitTests) {
dir('cloud-automation/Docker/python-nginx/python2.7-alpine3.7') {
sh 'sh dockerrun.sh --dryrun=True'
}
} else {
Utils.markStageSkippedForConditional(STAGE_NAME)
}
} catch (ex) {
metricsHelper.writeMetricWithResult(STAGE_NAME, false)
throw ex
}
metricsHelper.writeMetricWithResult(STAGE_NAME, true)
}
stage('python 3 base image dockerrun.sh test') {
try {
if(!skipUnitTests) {
dir('cloud-automation/Docker/python-nginx/python3.6-alpine3.7') {
sh 'sh dockerrun.sh --dryrun=True'
}
} else {
Utils.markStageSkippedForConditional(STAGE_NAME)
}
} catch (ex) {
metricsHelper.writeMetricWithResult(STAGE_NAME, false)
throw ex
}
metricsHelper.writeMetricWithResult(STAGE_NAME, true)
}
stage('WaitForQuayBuild') {
try {
if(!skipQuayImgBuildWait) {
quayHelper.waitForBuild(
"awshelper",
pipeConfig['currentBranchFormatted']
)
} else {
Utils.markStageSkippedForConditional(STAGE_NAME)
}
} catch (ex) {
metricsHelper.writeMetricWithResult(STAGE_NAME, false)
throw ex
}
metricsHelper.writeMetricWithResult(STAGE_NAME, true)
}
stage('SelectNamespace') {
try {
if(!doNotRunTests) {
(kubectlNamespace, lock) = kubeHelper.selectAndLockNamespace(pipeConfig['UID'], namespaces)
kubeLocks << lock
} else {
Utils.markStageSkippedForConditional(STAGE_NAME)
}
} catch (ex) {
metricsHelper.writeMetricWithResult(STAGE_NAME, false)
throw ex
}
metricsHelper.writeMetricWithResult(STAGE_NAME, true)
}
stage('ModifyManifest') {
try {
if(!doNotRunTests) {
manifestHelper.editService(
kubeHelper.getHostname(kubectlNamespace),
"awshelper",
pipeConfig.serviceTesting.branch
)
} else {
Utils.markStageSkippedForConditional(STAGE_NAME)
}
} catch (ex) {
metricsHelper.writeMetricWithResult(STAGE_NAME, false)
throw ex
}
metricsHelper.writeMetricWithResult(STAGE_NAME, true)
}
stage('K8sReset') {
try {
if(!doNotRunTests) {
// adding the reset-lock lock in case reset fails before unlocking
kubeLocks << kubeHelper.newKubeLock(kubectlNamespace, "gen3-reset", "reset-lock")
kubeHelper.reset(kubectlNamespace)
} else {
Utils.markStageSkippedForConditional(STAGE_NAME)
}
} catch (ex) {
metricsHelper.writeMetricWithResult(STAGE_NAME, false)
throw ex
}
metricsHelper.writeMetricWithResult(STAGE_NAME, true)
}
stage('VerifyClusterHealth') {
try {
if(!doNotRunTests) {
kubeHelper.waitForPods(kubectlNamespace)
testHelper.checkPodHealth(kubectlNamespace, "")
} else {
Utils.markStageSkippedForConditional(STAGE_NAME)
}
} catch (ex) {
metricsHelper.writeMetricWithResult(STAGE_NAME, false)
throw ex
}
metricsHelper.writeMetricWithResult(STAGE_NAME, true)
}
stage('GenerateData') {
try {
if(!doNotRunTests) {
testHelper.simulateData(kubectlNamespace)
} else {
Utils.markStageSkippedForConditional(STAGE_NAME)
}
} catch (ex) {
metricsHelper.writeMetricWithResult(STAGE_NAME, false)
throw ex
}
metricsHelper.writeMetricWithResult(STAGE_NAME, true)
}
stage('FetchDataClient') {
try {
if(!doNotRunTests) {
// we get the data client from master, unless the service being
// tested is the data client itself, in which case we get the
// executable for the current branch
dataCliBranch = "master"
if (pipeConfig.currentRepoName == "cdis-data-client") {
dataCliBranch = env.CHANGE_BRANCH
}
testHelper.fetchDataClient(dataCliBranch)
} else {
Utils.markStageSkippedForConditional(STAGE_NAME)
}
} catch (ex) {
metricsHelper.writeMetricWithResult(STAGE_NAME, false)
throw ex
}
metricsHelper.writeMetricWithResult(STAGE_NAME, true)
}
stage('RunTests') {
try {
if(!doNotRunTests) {
testHelper.runIntegrationTests(
kubectlNamespace,
pipeConfig.serviceTesting.name,
testedEnv,
"true",
listOfSelectedTests
)
} else {
Utils.markStageSkippedForConditional(STAGE_NAME)
}
} catch (ex) {
metricsHelper.writeMetricWithResult(STAGE_NAME, false)
throw ex
}
metricsHelper.writeMetricWithResult(STAGE_NAME, true)
}
stage('CleanS3') {
try {
if(!doNotRunTests) {
testHelper.cleanS3(kubectlNamespace)
} else {
Utils.markStageSkippedForConditional(STAGE_NAME)
}
} catch (ex) {
metricsHelper.writeMetricWithResult(STAGE_NAME, false)
throw ex
}
metricsHelper.writeMetricWithResult(STAGE_NAME, true)
}
stage('authzTest') {
try {
if(!doNotRunTests) {
// test revproxy+arborist /gen3-authz stuff
kubeHelper.kube(kubectlNamespace, {
sh('bash cloud-automation/gen3/bin/testsuite.sh --filter authz');
});
} else {
Utils.markStageSkippedForConditional(STAGE_NAME)
}
} catch (ex) {
metricsHelper.writeMetricWithResult(STAGE_NAME, false)
throw ex
}
metricsHelper.writeMetricWithResult(STAGE_NAME, true)
}
}
catch (e) {
pipelineHelper.handleError(e)
throw e
}
finally {
stage('Post') {
kubeHelper.teardown(kubeLocks)
testHelper.teardown()
if(!skipUnitTests) {
// tear down network policies deployed by the tests
kubeHelper.kube(kubectlNamespace, {
sh(script: 'kubectl --namespace="' + kubectlNamespace + '" delete networkpolicies --all', returnStatus: true);
});
pipelineHelper.teardown(currentBuild.result)
}
}
}
}