forked from couchbase/couchbase-jvm-clients
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
751 lines (672 loc) · 30.3 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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
// Want to make this matrix/parameterised, but:
// - Cannot make a proper matrix Jenkins project that's also pipeline
// - Seems to be no way to do e.g. multiple JDKs in a declarative pipeline
// - Can do it with scripted pipeline, but anything inside a node {} block won't trigger the post block, so can't gather junit results
// So, for now, everything is hard-coded. It's unlikely to change often.
// TODO: stashing the junit file after its generated and unstashing it in post, may work
LINUX_AGENTS = 'centos6||centos7||ubuntu16||ubuntu14||ubuntu20'
QUICK_TEST_MODE = false // enable to support quicker development iteration
// Java versions available through cbdeps are on
// https://hub.internal.couchbase.com/confluence/pages/viewpage.action?spaceKey=CR&title=cbdep+available+packages
// https://github.com/couchbasebuild/cbdep/blob/master/cbdep.config
def ORACLE_JDK = "java"
def ORACLE_JDK_8 = "8u192" // Avoid above Oracle 8u201, for licensing reasons.
def ORACLE_JDK_11 = "11.0.3"
def OPENJDK = "openjdk"
def OPENJDK_8 = "8u292-b10" // https://github.com/AdoptOpenJDK/openjdk8-binaries/releases
def OPENJDK_11 = "11.0.2+7"
def OPENJDK_11_M1 = "11.0.11+9"
def OPENJDK_17 = "17.0.1+12"
def CORRETTO = "corretto" // Amazon JDK
def CORRETTO_8 = "8.232.09.1" // available versions: https://docs.aws.amazon.com/corretto/latest/corretto-8-ug/doc-history.html
def CORRETTO_11 = "11.0.5.10.1" // available versions: https://docs.aws.amazon.com/corretto/latest/corretto-11-ug/doc-history.html
// The latest released cluster version. The majority of the testing is done against this.
def CLUSTER_VERSION_LATEST_STABLE = "7.1-stable"
// The lucky spammees
EMAILS = ['graham.pople@couchbase.com', 'michael.nitschinger@couchbase.com', 'david.nault@couchbase.com']
pipeline {
agent none
options {
// Safety check, prevent the script running forever
timeout(time: 600, unit: 'MINUTES')
}
stages {
stage('Build Scala 2.13 (OpenJDK 11)') {
agent { label "sdkqe" }
environment {
JAVA_HOME = "${WORKSPACE}/deps/${OPENJDK}-${OPENJDK_11}"
PATH = "${WORKSPACE}/deps/${OPENJDK}-${OPENJDK_11}/bin:$PATH"
}
when {
beforeAgent true;
expression
{ return IS_GERRIT_TRIGGER.toBoolean() == false }
}
steps {
buildScala(OPENJDK, OPENJDK_11, "2.13", "2.13.7", REFSPEC)
}
}
// Test against mock - this skips a lot of tests, and is intended for quick validation
stage('Validation testing (mock, Oracle JDK 8)') {
agent { label "sdkqe" }
environment {
JAVA_HOME = "${WORKSPACE}/deps/${ORACLE_JDK}-${ORACLE_JDK_8}"
PATH = "${WORKSPACE}/deps/${ORACLE_JDK}-${ORACLE_JDK_8}/bin:$PATH"
}
when {
beforeAgent true;
expression
{ return IS_GERRIT_TRIGGER.toBoolean() == true }
}
steps {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
cleanupWorkspace()
installJDKIfNeeded(ORACLE_JDK, ORACLE_JDK_8)
dir('couchbase-jvm-clients') {
doCheckout(REFSPEC)
// By default Java and Scala use mock for testing
shWithEcho("./mvnw -Dmaven.test.failure.ignore=true clean test")
// While iterating Jenkins development, this makes it much faster:
// shWithEcho("./mvnw package surefire:test -Dtest=com.couchbase.client.java.ObserveIntegrationTest -pl java-client")
}
}
}
post {
always {
// Process the Junit test results
junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
}
}
}
// "JDK testing" = checking the latest stable cluster against various JDK versions
// "Cluster testing" = checking a specific cluster version
// "JDK/Cluster testing" = orthogonally testing JDKs and clusters was expensive in time, so they are now combined.
// An arbitrary JDK is used for each cluster - aim is just to get good coverage of all of them.
// "Platform testing" = checking a specific platform (M1, ARM, Alpine etc.)
// "CE testing" = Community Edition testing
// Test against cbdyncluster - do for nightly tests
// One day can get all these cbdyncluster tests running in parallel: https://jenkins.io/blog/2017/09/25/declarative-1/
// No cluster testing for CLUSTER_VERSION_LATEST_STABLE since that is thoroughly tested by JVM tests
// No cluster testing for non-serverless 7.5, as that is dedicated to serverless
stage('Cluster testing (Linux, cbdyncluster 7.6.0-1228, Oracle JDK 8)') {
agent { label "sdkqe" }
environment {
JAVA_HOME = "${WORKSPACE}/deps/${ORACLE_JDK}-${ORACLE_JDK_8}"
PATH = "${WORKSPACE}/deps/${ORACLE_JDK}-${ORACLE_JDK_8}/bin:$PATH"
}
when {
beforeAgent true;
expression
{ return IS_GERRIT_TRIGGER.toBoolean() == false }
}
steps {
test(ORACLE_JDK, ORACLE_JDK_8, "7.6.0-1228", REFSPEC)
}
post {
always {
junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
}
}
}
stage('JDK/Cluster testing (Linux, cbdyncluster 7.2-stable, Oracle JDK 8)') {
agent { label "sdkqe" }
environment {
JAVA_HOME = "${WORKSPACE}/deps/${ORACLE_JDK}-${ORACLE_JDK_8}"
PATH = "${WORKSPACE}/deps/${ORACLE_JDK}-${ORACLE_JDK_8}/bin:$PATH"
}
when {
beforeAgent true;
expression
{ return IS_GERRIT_TRIGGER.toBoolean() == false }
}
steps {
test(ORACLE_JDK, ORACLE_JDK_8, "7.2-stable", REFSPEC)
}
post {
always {
junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
}
}
}
stage('JDK/Cluster testing (Linux, cbdyncluster 7.1-stable, openjdk 17)') {
agent { label "sdkqe" }
environment {
JAVA_HOME = "${WORKSPACE}/deps/${OPENJDK}-${OPENJDK_17}"
PATH = "${WORKSPACE}/deps/${OPENJDK}-${OPENJDK_17}/bin:$PATH"
}
when {
beforeAgent true;
expression
{ return IS_GERRIT_TRIGGER.toBoolean() == false }
}
steps {
test(OPENJDK, OPENJDK_17, "7.1-stable", REFSPEC)
}
post {
always {
junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
}
}
}
stage('JDK/Cluster testing (Linux, cbdyncluster 7.0-stable, Oracle JDK 11)') {
agent { label "sdkqe" }
environment {
JAVA_HOME = "${WORKSPACE}/deps/${ORACLE_JDK}-${ORACLE_JDK_11}"
PATH = "${WORKSPACE}/deps/${ORACLE_JDK}-${ORACLE_JDK_11}/bin:$PATH"
}
when {
beforeAgent true;
expression
{ return IS_GERRIT_TRIGGER.toBoolean() == false }
}
steps {
test(ORACLE_JDK, ORACLE_JDK_11, "7.0-stable", REFSPEC)
}
post {
always {
junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
}
}
}
stage('JDK/Cluster testing (Linux, cbdyncluster 6.6-stable, Corretto 8)') {
agent { label "sdkqe" }
environment {
JAVA_HOME = "${WORKSPACE}/deps/${CORRETTO}-${CORRETTO_8}"
PATH = "${WORKSPACE}/deps/${CORRETTO}-${CORRETTO_8}/bin:$PATH"
}
when {
beforeAgent true;
expression
{ return IS_GERRIT_TRIGGER.toBoolean() == false }
}
steps {
test(CORRETTO, CORRETTO_8, "6.6-stable", REFSPEC)
}
post {
always {
junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
}
}
}
// 6.5 is EOL, we do one sanity test against it
stage('JDK/Cluster testing (Linux, cbdyncluster 6.5-release, Corretto 11)') {
agent { label "sdkqe" }
environment {
JAVA_HOME = "${WORKSPACE}/deps/${CORRETTO}-${CORRETTO_11}"
PATH = "${WORKSPACE}/deps/${CORRETTO}-${CORRETTO_11}/bin:$PATH"
}
when {
beforeAgent true;
expression
{ return IS_GERRIT_TRIGGER.toBoolean() == false }
}
steps {
test(CORRETTO, CORRETTO_11, "6.5-release", REFSPEC)
}
post {
always {
junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
}
}
}
// 6.0 is EOL, we do one sanity test against it
stage('JDK/Cluster testing (Linux, cbdyncluster 6.0-release, openjdk 11)') {
agent { label "sdkqe" }
environment {
JAVA_HOME = "${WORKSPACE}/deps/${OPENJDK}-${OPENJDK_11}"
PATH = "${WORKSPACE}/deps/${OPENJDK}-${OPENJDK_11}/bin:$PATH"
}
when {
beforeAgent true;
expression
{ return IS_GERRIT_TRIGGER.toBoolean() == false }
}
steps {
test(OPENJDK, OPENJDK_11, "6.0-release", REFSPEC)
}
post {
always {
junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
}
}
}
// When removing tests for an older cluster version, if it's a JDK/Cluster test please
// make sure that JDK is still tested.
// 7.5 is dedicated to serverless
// Cannot be run due to issues with indexer service in --serverless-mode: https://couchbase.slack.com/archives/CFM4D3VFU/p1689590660024819
// Real Elixir is tested in job: http://qe-jenkins.sc.couchbase.com/job/DirectNebulaJob-centos-sdk/
// stage('Serverless testing (Linux, cbdyncluster 7.5-stable Serverless mode, Oracle JDK 8)') {
// agent { label "sdkqe" }
// environment {
// JAVA_HOME = "${WORKSPACE}/deps/${ORACLE_JDK}-${ORACLE_JDK_8}"
// PATH = "${WORKSPACE}/deps/${ORACLE_JDK}-${ORACLE_JDK_8}/bin:$PATH"
// }
// when {
// beforeAgent true;
// expression
// { return IS_GERRIT_TRIGGER.toBoolean() == false }
// }
// steps {
// test(ORACLE_JDK, ORACLE_JDK_8, "7.5-stable", includeEventing : true, serverlessMode: true, REFSPEC)
// }
// post {
// always {
// junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
// }
// }
// }
// Cannot use 7.1-stable, it maps to 7.1.3 and there is no 7.1.3 CE release. 7.1.1 is current latest (Nov '22).
stage("CE testing (Linux, cbdyncluster 7.1.1, OpenJDK 8)") {
agent { label "sdkqe" }
environment {
JAVA_HOME = "${WORKSPACE}/deps/${OPENJDK}-${OPENJDK_8}"
PATH = "${WORKSPACE}/deps/${OPENJDK}-${OPENJDK_8}/bin:$PATH"
}
when {
beforeAgent true;
expression
{ return IS_GERRIT_TRIGGER.toBoolean() == false }
}
steps {
test(OPENJDK, OPENJDK_8, "7.1.1", ceMode : true, REFSPEC)
}
post {
always {
junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
}
}
}
// 7.0.3 does not and will not have a CE build.
stage('CE testing (Linux, cbdyncluster 7.0.2, Oracle JDK 8)') {
agent { label "sdkqe" }
environment {
JAVA_HOME = "${WORKSPACE}/deps/${ORACLE_JDK}-${ORACLE_JDK_8}"
PATH = "${WORKSPACE}/deps/${ORACLE_JDK}-${ORACLE_JDK_8}/bin:$PATH"
}
when {
beforeAgent true;
expression
{ return IS_GERRIT_TRIGGER.toBoolean() == false }
}
steps {
test(ORACLE_JDK, ORACLE_JDK_8, "7.0.2", ceMode : true, REFSPEC)
}
post {
always {
junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
}
}
}
stage("Platform testing (M1, stable, openjdk 11)") {
agent { label 'm1' }
environment {
// Advice from builds team: '"java" doesn't support Linux aarch64. Only openjdk.'
JAVA_HOME = "${WORKSPACE}/deps/${OPENJDK}-${OPENJDK_11_M1}"
PATH = "${WORKSPACE}/deps/${OPENJDK}-${OPENJDK_11_M1}/bin:$PATH"
}
when {
beforeAgent true;
expression
{ return IS_GERRIT_TRIGGER.toBoolean() == false }
}
steps {
test(OPENJDK, OPENJDK_11_M1, CLUSTER_VERSION_LATEST_STABLE, REFSPEC)
}
post {
always {
junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
}
}
}
stage('Platform testing (Graviton2, mocks, openjdk 11)') {
agent { label 'qe-grav2-amzn2' }
environment {
// Advice from builds team: '"java" doesn't support Linux aarch64. Only openjdk.'
JAVA_HOME = "${WORKSPACE}/deps/${OPENJDK}-${OPENJDK_11}"
PATH = "${WORKSPACE}/deps/${OPENJDK}-${OPENJDK_11}/bin:${WORKSPACE}/deps/maven-3.5.2-cb6/bin:$PATH"
}
when {
beforeAgent true;
expression
{ return IS_GERRIT_TRIGGER.toBoolean() == false }
}
steps {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
cleanupWorkspace()
installJDKIfNeeded(OPENJDK, OPENJDK_11)
// qe-grav2-amzn2 doesn't have maven
shWithEcho("cbdep install -d deps maven 3.5.2-cb6")
dir('couchbase-jvm-clients') {
doCheckout(REFSPEC)
// Advice from builds team: cbdyncluster cannot be contacted from qe-grav2-amzn2, so testing
// against mocks only for now
script { testAgainstMock() }
}
}
}
post {
always {
junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
}
}
}
// Temporarily disabling until JVMCBC-1227 is resolved
// stage('Platform testing (Alpine, mock, openjdk 11)') {
// agent { label 'alpine' }
// environment {
// JAVA_HOME = "${WORKSPACE}/deps/${OPENJDK}-${OPENJDK_11_M1}"
// PATH = "${WORKSPACE}/deps/${OPENJDK}-${OPENJDK_11_M1}/bin:$PATH"
// }
// when {
// beforeAgent true;
// expression
// { return IS_GERRIT_TRIGGER.toBoolean() == false }
// }
// steps {
// catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
// cleanupWorkspace()
// installJDKIfNeeded(OPENJDK, OPENJDK_11_M1)
// dir('couchbase-jvm-clients') {
// doCheckout(REFSPEC)
// // Mock testing only, with native IO disabled - check JVMCBC-942 for details
// script { testAgainstMock(true) }
// }
// }
// }
// post {
// always {
// junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
// }
// }
// }
stage('Platform testing (ARM Ubuntu 20, mock, openjdk 17)') {
agent { label 'qe-ubuntu20-arm64' }
environment {
JAVA_HOME = "${WORKSPACE}/deps/${OPENJDK}-${OPENJDK_17}"
PATH = "${WORKSPACE}/deps/${OPENJDK}-${OPENJDK_17}/bin:$PATH"
}
when {
beforeAgent true;
expression
{ return IS_GERRIT_TRIGGER.toBoolean() == false }
}
steps {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
cleanupWorkspace()
installJDKIfNeeded(OPENJDK, OPENJDK_17)
dir('couchbase-jvm-clients') {
doCheckout(REFSPEC)
// Cbdyn not available on this machine
script {
shWithEcho("make deps-only")
shWithEcho("./mvnw --fail-at-end clean install --batch-mode")
}
}
}
}
post {
always {
junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
}
}
}
// Commented for now as sdk-integration-test-win temporarily down
// stage('testing (Windows, cbdyncluster 6.5, Oracle JDK 8)') {
// agent { label 'sdk-integration-test-win' }
// environment {
// JAVA_HOME = "${WORKSPACE}/deps/${ORACLE_JDK}-${ORACLE_JDK_8}"
// PATH = "${WORKSPACE}/deps/${ORACLE_JDK}-${ORACLE_JDK_8}/bin:$PATH"
// }
// when {
// expression
// { return IS_GERRIT_TRIGGER.toBoolean() == false }
// }
// steps {
// catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
// cleanWs()
// unstash 'couchbase-jvm-clients'
// installJDKIfNeeded("windows", ORACLE_JDK, ORACLE_JDK_8)
//
// dir('couchbase-jvm-clients') {
// script {
// testAgainstServer(SERVER_TEST_VERSION, QUICK_TEST_MODE)
// }
// }
// }
// }
// post {
// always {
// // Process the Junit test results
// junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
// }
// }
// }
}
post {
failure { emailFailure() }
success { emailSuccess() }
}
}
void test(Map args=[:],
String jdk,
String jdkVersion,
String serverVersion,
String refspec) {
boolean ceMode = args.containsKey("ceMode") ? args.get("ceMode") : false
boolean includeAnalytics = args.containsKey("includeAnalytics") ? args.get("includeAnalytics") : !ceMode // CE doesn't have analytics
boolean includeEventing = args.containsKey("includeEventing") ? args.get("includeEventing") : false
boolean enableDevelopPreview = args.containsKey("enableDevelopPreview") ? args.get("enableDevelopPreview") : false
boolean multiCerts = args.containsKey("multiCerts") ? args.get("multiCerts") : false
boolean serverlessMode = args.containsKey("serverlessMode") ? args.get("serverlessMode") : false
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
cleanupWorkspace()
installJDKIfNeeded(jdk, jdkVersion)
dir('couchbase-jvm-clients') {
doCheckout(refspec)
script { testAgainstServer(serverVersion, QUICK_TEST_MODE, includeAnalytics, includeEventing, enableDevelopPreview, ceMode, multiCerts, serverlessMode) }
}
}
}
void buildScala(String jdk,
String jdkVersion,
String scalaCompatVersion,
String scalaLibraryVersion,
String refspec) {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
cleanupWorkspace()
installJDKIfNeeded(jdk, jdkVersion)
dir('couchbase-jvm-clients') {
doCheckout(refspec)
shWithEcho("make deps-only")
shWithEcho("./mvnw -Dmaven.test.skip --batch-mode -Dscala.compat.version=${scalaCompatVersion} -Dscala.compat.library.version=${scalaLibraryVersion} clean compile")
}
}
}
void doCheckout(refspec) {
checkout([$class: 'GitSCM', userRemoteConfigs: [[url: '$REPO']]])
if (refspec != '' && refspec != null) {
echo 'Applying REFSPEC'
checkout([$class: 'GitSCM', branches: [[name: "FETCH_HEAD"]], userRemoteConfigs: [[refspec: "$refspec", url: "https://review.couchbase.org/couchbase-jvm-clients"]]])
sh(script: "git log -n 2")
}
}
void emailSuccess() {
EMAILS.each {
def email = it
mail to: email,
subject: "Successful Pipeline: ${currentBuild.fullDisplayName}",
body: "Succeeded: ${env.BUILD_URL}"
}
}
void emailFailure() {
EMAILS.each {
def email = it
mail to: email,
subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
body: "Something is wrong with ${env.BUILD_URL}: ${env.FAILED_TESTS}"
}
}
void shWithEcho(String command) {
if (NODE_NAME.contains("windows")) {
echo bat(script: command, returnStdout: true)
} else {
echo sh(script: command, returnStdout: true)
}
}
void shIgnoreFailure(String command) {
if (NODE_NAME.contains("windows")) {
bat(script: command, returnStatus: true)
} else {
sh(script: command, returnStatus: true)
}
}
// Installs JDK to the workspace using cbdep tool
String installJDKIfNeeded(javaPackage, javaVersion) {
def install = false
echo "checking install"
if (!fileExists("deps")) {
echo "file deps does not exist"
install = true
} else {
echo "file deps does exist"
dir("deps") {
install = !fileExists("$javaPackage-${javaVersion}")
if (install) {
echo "$javaPackage-${javaVersion} exists"
} else {
echo "$javaPackage-${javaVersion} does not exist"
}
}
}
if (install) {
shWithEcho("mkdir -p deps && mkdir -p deps/$javaPackage-${javaVersion}")
shWithEcho("cbdep install -d deps $javaPackage ${javaVersion}")
}
}
void createIntegrationTestPropertiesFile(String filename, String ip) {
shWithEcho("echo 'cluster.type=unmanaged' > ${filename}")
shWithEcho("echo 'cluster.adminUsername=Administrator' >> ${filename}")
shWithEcho("echo 'cluster.adminPassword=password' >> ${filename}")
shWithEcho("echo 'cluster.unmanaged.seed=${ip}:8091' >> ${filename}")
shWithEcho("echo 'cluster.unmanaged.numReplicas=0' >> ${filename}")
shWithEcho("cat ${filename}")
}
// To be called inside a script {} block - required so can do try-finally logic to cleanup the cbdyncluster
// (Inside a script {} block is 'scripted pipeline' syntax, different to the 'declarative pipeline' syntax elsewhere.)
void testAgainstServer(String serverVersion,
boolean QUICK_TEST_MODE,
boolean includeAnalytics = true,
boolean includeEventing = false,
boolean enableDevelopPreview = false,
boolean ceMode = false,
boolean multiCerts = false,
boolean serverlessMode = false) {
def clusterId = null
try {
// For debugging
shIgnoreFailure("echo $JAVA_HOME")
shIgnoreFailure("ls $JAVA_HOME")
shIgnoreFailure("echo $PATH")
shIgnoreFailure("java -version")
// For debugging, what clusters are open
shWithEcho("cbdyncluster ps -a")
// May need to remove some manually if they're stuck. -f forces, allows deleting cluster we didn't open
// shWithEcho("cbdyncluster rm -f 3d023261")
// Allocate the cluster
def script = "cbdyncluster allocate --num-nodes=3 ${ceMode ? ' --use-ce=true' : ''} --server-version=${serverVersion}"
if (serverlessMode) {
script += " --serverless-mode"
}
echo "Running " + script
clusterId = sh(script: script, returnStdout: true).trim()
echo "Got cluster ID $clusterId"
// Find the cluster IP
def ips = sh(script: "cbdyncluster ips $clusterId", returnStdout: true).trim()
echo "Got raw cluster IPs " + ips
def ip = ips.tokenize(',')[0]
echo "Got cluster IP http://" + ip + ":8091"
// By default Java and Scala use mock for testing, make them use cbdyncluster instead
createIntegrationTestPropertiesFile('core-io/src/integrationTest/resources/integration.properties', ip)
createIntegrationTestPropertiesFile('java-client/src/integrationTest/resources/integration.properties', ip)
createIntegrationTestPropertiesFile('scala-client/src/integrationTest/resources/integration.properties', ip)
createIntegrationTestPropertiesFile('kotlin-client/src/integrationTest/resources/integration.properties', ip)
// We need a bit more than the default 600 for out bucket management integration tests
// Particularly Magma which requires min of 1GB
def ramQuota = 1500
// Create the cluster
if (!QUICK_TEST_MODE) {
def services = "kv,index,n1ql,fts${includeAnalytics ? ',cbas' : ''}${includeEventing ? ',eventing' : ''}"
shWithEcho("cbdyncluster --node $services --node kv --node kv --bucket default --ram-quota $ramQuota setup $clusterId")
} else {
// During development, this is faster (less tests)
shWithEcho("cbdyncluster --node kv --node kv --node kv --bucket default --ram-quota $ramQuota setup $clusterId")
}
// Make sure the cluster stays up during all tests (the finally block below ensures that it's always pulled down)
shWithEcho("cbdyncluster refresh $clusterId 2h")
// Just for debugging, log some cluster details
try {
shWithEcho("curl -u Administrator:password http://" + ip + ":8091/pools")
shWithEcho("curl -u Administrator:password http://" + ip + ":8091/pools/default")
}
catch (RuntimeException ex) {
echo "Exception while getting debugging info ${ex}"
}
// Make the bucket flushable
shWithEcho("curl -v -X POST -u Administrator:password -d flushEnabled=1 http://" + ip + ":8091/pools/default/buckets/default")
// Set the query indexer mode. Without this query tests fail with "GSI CreatePrimaryIndex() - cause: Please Set Indexer Storage Mode Before Create Index"
shWithEcho("curl -v -X POST -u Administrator:password -d 'storageMode=${ceMode ? 'forestdb' : 'plasma'}' http://" + ip + ":8091/settings/indexes")
if (enableDevelopPreview) {
shWithEcho("curl -v -X POST -u Administrator:password -d 'enabled=true' http://" + ip + ":8091/settings/developerPreview")
}
if (multiCerts) {
shWithEcho("mkdir certs")
shWithEcho("cbdyncluster setup-cert-auth $clusterId --user Administrator --num-roots 2 --out-dir=certs")
shWithEcho("echo 'cluster.unmanaged.certsFile=${WORKSPACE}/couchbase-jvm-clients/certs/ca.pem' >> java-client/src/integrationTest/resources/integration.properties")
shWithEcho("echo 'cluster.unmanaged.certsFile=${WORKSPACE}/couchbase-jvm-clients/certs/ca.pem' >> scala-client/src/integrationTest/resources/integration.properties")
}
// Not sure why this is needed, it should be in stash from build....
shWithEcho("make deps-only")
// The --batch-mode hides download progress messages, very verbose
if (!QUICK_TEST_MODE) {
shWithEcho("./mvnw -Dmaven.test.failure.ignore=true clean install --batch-mode -Dgroups=!flaky")
} else {
// This is for iteration during development, skips out some steps
shWithEcho("./mvnw -pl '!scala-client,!scala-implicits' --fail-at-end clean install test --batch-mode")
// Another iteration option, this runs just one test
//shWithEcho("./mvnw package surefire:test -Dtest=com.couchbase.client.java.ObserveIntegrationTest -pl java-client")
}
}
finally {
if (clusterId != null) {
// Easy to run out of resources during iterating, so cleanup even
// though cluster will be auto-removed after a time
sh(script: "cbdyncluster rm $clusterId")
}
}
}
void testAgainstMock(boolean disableNativeIo = false) {
shWithEcho("make deps-only")
shWithEcho("./mvnw -Dmaven.test.failure.ignore=true clean install --batch-mode ${disableNativeIo ? '-Dcom.couchbase.client.core.deps.io.netty.transport.noNative=true' : ''}")
}
void cleanupWorkspace() {
dir("${workspace}") {
sh 'ls'
}
// This _might_ clean the workspace now, or it may clean it after the build: the docs are unclear: one place says
// "Delete workspace when build is done", another indicates it's an imperative command.
// So, also doing the deleteDir() steps below, perhaps redundantly.
cleanWs()
dir("${workspace}") {
sh 'ls'
deleteDir()
sh 'ls'
}
// Per https://stackoverflow.com/questions/37468455/jenkins-pipeline-wipe-out-workspace, there are directories the
// above will not delete
dir("${workspace}@tmp") {
deleteDir()
}
dir("${workspace}@script") {
deleteDir()
}
}