forked from datastax/nodejs-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
580 lines (534 loc) · 17.7 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
#!groovy
def initializeEnvironment() {
def nodeVersions = ['16': '16.20.2', '18': '18.17.1', '20': '20.5.1']
env.DRIVER_DISPLAY_NAME = 'Cassandra Node.js Driver'
env.DRIVER_METRIC_TYPE = 'oss'
if (env.GIT_URL.contains('riptano/nodejs-driver')) {
env.DRIVER_DISPLAY_NAME = 'private ' + env.DRIVER_DISPLAY_NAME
env.DRIVER_METRIC_TYPE = 'oss-private'
} else if (env.GIT_URL.contains('nodejs-dse-driver')) {
env.DRIVER_DISPLAY_NAME = 'DSE Node.js Driver'
env.DRIVER_METRIC_TYPE = 'dse'
}
env.GIT_SHA = "${env.GIT_COMMIT.take(7)}"
env.GITHUB_PROJECT_URL = "https://${GIT_URL.replaceFirst(/(git@|http:\/\/|https:\/\/)/, '').replace(':', '/').replace('.git', '')}"
env.GITHUB_BRANCH_URL = "${GITHUB_PROJECT_URL}/tree/${env.BRANCH_NAME}"
env.GITHUB_COMMIT_URL = "${GITHUB_PROJECT_URL}/commit/${env.GIT_COMMIT}"
env.NODEJS_VERSION_FULL = nodeVersions[env.NODEJS_VERSION]
sh label: 'Assign Node.js global environment', script: '''#!/bin/bash -lex
nodenv versions
echo "Using Node.js runtime ${NODEJS_VERSION} (${NODEJS_VERSION_FULL})"
nodenv global ${NODEJS_VERSION_FULL}
'''
sh label: 'Download Apache Cassandra or DataStax Enterprise', script: '''#!/bin/bash -lex
. ${CCM_ENVIRONMENT_SHELL} ${CASSANDRA_VERSION}
'''
if (env.CASSANDRA_VERSION.split('-')[0] == 'dse') {
env.DSE_FIXED_VERSION = env.CASSANDRA_VERSION.split('-')[1]
sh label: 'Update environment for DataStax Enterprise', script: '''#!/bin/bash -le
cat >> ${HOME}/environment.txt << ENVIRONMENT_EOF
CCM_PATH=${HOME}/ccm
CCM_CASSANDRA_VERSION=${DSE_FIXED_VERSION} # maintain for backwards compatibility
CCM_VERSION=${DSE_FIXED_VERSION}
CCM_SERVER_TYPE=dse
DSE_VERSION=${DSE_FIXED_VERSION}
CCM_IS_DSE=true
CCM_BRANCH=${DSE_FIXED_VERSION}
DSE_BRANCH=${DSE_FIXED_VERSION}
ENVIRONMENT_EOF
'''
}
sh label: 'Display Node.js and environment information', script: '''#!/bin/bash -le
# Load CCM environment variables
set -o allexport
. ${HOME}/environment.txt
set +o allexport
node --version
npm --version
printenv | sort
'''
}
def installDriverAndDependencies() {
sh label: 'Install the driver', script: '''#!/bin/bash -lex
npm install
'''
sh label: 'Install driver dependencies', script: '''#!/bin/bash -lex
npm install mocha-jenkins-reporter@0
npm install kerberos@1
npm install -g eslint@4
'''
}
def executeLinter() {
sh label: 'Perform static analysis of source code', script: '''#!/bin/bash -lex
npm run eslint
'''
}
def executeTests() {
sh label: 'Execute tests', script: '''#!/bin/bash -lex
# Load CCM environment variables
set -o allexport
. ${HOME}/environment.txt
set +o allexport
# Fix Java version at Java8 for now because of dependencies in DSE.
# TODO: This should last us through testing against Cassandra 4.1.x at least but
# will eventually need to be made more generic.
. ${JABBA_SHELL}
jabba use 1.8
npm run ci_jenkins
'''
}
def executeExamples() {
sh label: 'Create CCM cluster for examples', script: '''#!/bin/bash -lex
# Load CCM environment variables
set -o allexport
. ${HOME}/environment.txt
set +o allexport
ccm create test_samples --dse -v ${CCM_VERSION} -n 1:0 -b -s
'''
sh label: 'Execute examples', script: '''#!/bin/bash -lex
set -o allexport
. ${HOME}/environment.txt
set +o allexport
(
cd examples
npm install
node runner.js
)
'''
sh label: 'Clean-up CCM cluster for examples', script: '''#!/bin/bash -lex
ccm remove
'''
}
def notifySlack(status = 'started') {
// Set the global pipeline scoped environment (this is above each matrix)
env.BUILD_STATED_SLACK_NOTIFIED = 'true'
def buildType = 'Commit'
if (params.CI_SCHEDULE != 'DO-NOT-CHANGE-THIS-SELECTION') {
buildType = "${params.CI_SCHEDULE.toLowerCase().capitalize()}"
}
def color = 'good' // Green
if (status.equalsIgnoreCase('aborted')) {
color = '808080' // Grey
} else if (status.equalsIgnoreCase('unstable')) {
color = 'warning' // Orange
} else if (status.equalsIgnoreCase('failed')) {
color = 'danger' // Red
}
def message = """Build ${status} for ${env.DRIVER_DISPLAY_NAME} [${buildType}]
<${env.GITHUB_BRANCH_URL}|${env.BRANCH_NAME}> - <${env.RUN_DISPLAY_URL}|#${env.BUILD_NUMBER}> - <${env.GITHUB_COMMIT_URL}|${env.GIT_SHA}>"""
if (!status.equalsIgnoreCase('Started')) {
message += """
${status} after ${currentBuild.durationString - ' and counting'}"""
}
slackSend color: "${color}",
channel: "#nodejs-driver-dev-bots",
message: "${message}"
}
def describePerCommitStage() {
script {
currentBuild.displayName = "Per-Commit"
currentBuild.description = '''Per-Commit build and testing'''
}
}
def describeScheduledTestingStage() {
script {
def type = params.CI_SCHEDULE.toLowerCase().capitalize()
currentBuild.displayName = "${type} schedule"
currentBuild.description = "${type} scheduled build and testing of all supported Apache Cassandra and DataStax " +
"Enterprise against multiple Node.js runtimes"
}
}
def describeAdhocTestingStage() {
script {
def serverType = params.ADHOC_BUILD_AND_EXECUTE_TESTS_SERVER_VERSION.split('-')[0]
def serverDisplayName = 'Apache Cassandra'
def serverVersion = " v${serverType}"
if (serverType == 'ALL') {
serverDisplayName = "all ${serverDisplayName} and DataStax Enterprise server versions"
serverVersion = ''
} else {
try {
serverVersion = " v${env.ADHOC_BUILD_AND_EXECUTE_TESTS_SERVER_VERSION.split('-')[1]}"
} catch (e) {
;; // no-op
}
if (serverType == 'ddac') {
serverDisplayName = "DataStax Distribution of ${serverDisplayName}"
} else if (serverType == 'dse') {
serverDisplayName = 'DataStax Enterprise'
}
}
def nodeJsVersionInformation = "Node.js v${params.ADHOC_BUILD_AND_EXECUTE_TESTS_NODEJS_VERSION}"
if (params.ADHOC_BUILD_AND_EXECUTE_TESTS_NODEJS_VERSION == 'ALL') {
nodeJsVersionInformation = 'all Node.js versions'
}
def examplesInformation = ''
if (ADHOC_BUILD_AND_EXECUTE_TESTS_EXECUTE_EXAMPLES) {
examplesInformation = ' with examples'
}
currentBuild.displayName = "${params.ADHOC_BUILD_AND_EXECUTE_TESTS_SERVER_VERSION} against ${nodeJsVersionInformation}"
currentBuild.description = "Testing ${serverDisplayName} ${serverVersion} against ${nodeJsVersionInformation}${examplesInformation}"
}
}
// branch pattern for cron
def branchPatternCron() {
~"(master)"
}
pipeline {
agent none
// Global pipeline timeout
options {
disableConcurrentBuilds()
timeout(time: 5, unit: 'HOURS')
buildDiscarder(logRotator(artifactNumToKeepStr: '10', // Keep only the last 10 artifacts
numToKeepStr: '50')) // Keep only the last 50 build records
}
parameters {
choice(
name: 'ADHOC_BUILD_TYPE',
choices: ['BUILD', 'BUILD-AND-EXECUTE-TESTS'],
description: '''<p>Perform a adhoc build operation</p>
<table style="width:100%">
<col width="25%">
<col width="75%">
<tr>
<th align="left">Choice</th>
<th align="left">Description</th>
</tr>
<tr>
<td><strong>BUILD</strong></td>
<td>Performs a <b>Per-Commit</b> build</td>
</tr>
<tr>
<td><strong>BUILD-AND-EXECUTE-TESTS</strong></td>
<td>Performs a build and executes the integration and unit tests</td>
</tr>
</table>''')
choice(
name: 'ADHOC_BUILD_AND_EXECUTE_TESTS_NODEJS_VERSION',
choices: ['16', '18', '20', 'ALL'],
description: 'Node.js version to use for adhoc <b>BUILD-AND-EXECUTE-TESTS</b> <strong>ONLY!</strong>')
choice(
name: 'ADHOC_BUILD_AND_EXECUTE_TESTS_SERVER_VERSION',
choices: [
'3.11', // Current Apache Cassandra
'4.0', // Development Apache Cassandra
'dse-5.1.35', // Legacy DataStax Enterprise
'dse-6.8.30', // Development DataStax Enterprise
'ALL'],
description: '''Apache Cassandra and DataStax Enterprise server version to use for adhoc <b>BUILD-AND-EXECUTE-TESTS</b> <strong>ONLY!</strong>
<table style="width:100%">
<col width="15%">
<col width="85%">
<tr>
<th align="left">Choice</th>
<th align="left">Description</th>
</tr>
<tr>
<td><strong>3.11</strong></td>
<td>Apache Cassandra v3.11.x</td>
</tr>
<tr>
<td><strong>4.0</strong></td>
<td>Apache Cassandra v4.x (<b>CURRENTLY UNDER DEVELOPMENT</b>)</td>
</tr>
<tr>
<td><strong>dse-5.1</strong></td>
<td>DataStax Enterprise v5.1.x</td>
</tr>
<tr>
<td><strong>dse-6.8</strong></td>
<td>DataStax Enterprise v6.8.x (<b>CURRENTLY UNDER DEVELOPMENT</b>)</td>
</tr>
</table>''')
booleanParam(
name: 'ADHOC_BUILD_AND_EXECUTE_TESTS_EXECUTE_EXAMPLES',
defaultValue: false,
description: 'Flag to determine if the examples should be executed for adhoc builds')
booleanParam(
name: 'JUNIT_REPORT_STACK',
defaultValue: true,
description: 'Flag to determine if stack trace should be enabled with test failures for scheduled or adhoc builds')
booleanParam(
name: 'TEST_TRACE',
defaultValue: true,
description: 'Flag to determine if test tracing should be enabled for scheduled or adhoc builds')
choice(
name: 'CI_SCHEDULE',
choices: ['DO-NOT-CHANGE-THIS-SELECTION', 'WEEKNIGHTS'],
description: 'CI testing schedule to execute periodically scheduled builds and tests of the driver (<strong>DO NOT CHANGE THIS SELECTION</strong>)')
}
triggers {
parameterizedCron(branchPatternCron().matcher(env.BRANCH_NAME).matches() ? """
# Every weeknight (Monday - Friday) around 7 PM
H 19 * * 1-5 %CI_SCHEDULE=WEEKNIGHTS
""" : "")
}
environment {
OS_VERSION = 'ubuntu/jammy64/nodejs-driver'
JUNIT_REPORT_STACK = "${params.JUNIT_REPORT_STACK ? '1' : '0'}"
JUNIT_REPORT_PATH = '.'
TEST_TRACE = "${params.TEST_TRACE ? 'on' : 'off'}"
SIMULACRON_PATH = '/home/jenkins/simulacron.jar'
CCM_PATH = '/home/jenkins/ccm'
CCM_ENVIRONMENT_SHELL = '/usr/local/bin/ccm_environment.sh'
JABBA_SHELL = '/usr/lib/jabba/jabba.sh'
}
stages {
stage('Per-Commit') {
when {
beforeAgent true
allOf {
expression { params.ADHOC_BUILD_TYPE == 'BUILD' }
expression { params.CI_SCHEDULE == 'DO-NOT-CHANGE-THIS-SELECTION' }
not { buildingTag() }
}
}
matrix {
axes {
axis {
name 'CASSANDRA_VERSION'
values '3.11', // Current Apache Cassandra
'4.0', // Development Apache Cassandra
'dse-5.1.35', // Legacy DataStax Enterprise
'dse-6.8.30' // Development DataStax Enterprise
}
axis {
name 'NODEJS_VERSION'
values '16', '18', '20'
}
}
agent {
label "${OS_VERSION}"
}
stages {
stage('Initialize-Environment') {
steps {
initializeEnvironment()
script {
if (env.BUILD_STATED_SLACK_NOTIFIED != 'true') {
notifySlack()
}
}
}
}
stage('Describe-Build') {
steps {
describePerCommitStage()
}
}
stage('Install-Driver-And-Dependencies') {
steps {
installDriverAndDependencies()
}
}
stage('Execute-Linter') {
steps {
executeLinter()
}
}
stage('Execute-Tests') {
steps {
catchError { // Handle error conditions in the event examples should be executed
executeTests()
}
}
post {
always {
junit testResults: '*.xml'
}
}
}
stage('Execute-Examples') {
when {
expression { env.CASSANDRA_VERSION == 'dse-6.8.30' }
}
steps {
executeExamples()
}
}
}
}
post {
aborted {
notifySlack('aborted')
}
success {
notifySlack('completed')
}
unstable {
notifySlack('unstable')
}
failure {
notifySlack('FAILED')
}
}
}
stage('Scheduled-Testing') {
when {
beforeAgent true
branch pattern: '((\\d+(\\.[\\dx]+)+)|dse|master)', comparator: 'REGEXP'
allOf {
expression { params.ADHOC_BUILD_TYPE == 'BUILD' }
expression { params.CI_SCHEDULE != 'DO-NOT-CHANGE-THIS-SELECTION' }
not { buildingTag() }
}
}
matrix {
axes {
axis {
name 'CASSANDRA_VERSION'
values '3.11', // Current Apache Cassandra
'4.0', // Development Apache Cassandra
'dse-5.1.35', // Legacy DataStax Enterprise
'dse-6.8.30' // Development DataStax Enterprise
}
axis {
name 'NODEJS_VERSION'
values '16', '18', '20'
}
}
agent {
label "${OS_VERSION}"
}
stages {
stage('Initialize-Environment') {
steps {
initializeEnvironment()
script {
if (env.BUILD_STATED_SLACK_NOTIFIED != 'true') {
notifySlack()
}
}
}
}
stage('Describe-Build') {
steps {
describeScheduledTestingStage()
}
}
stage('Install-Driver-And-Dependencies') {
steps {
installDriverAndDependencies()
}
}
stage('Execute-Linter') {
steps {
executeLinter()
}
}
stage('Execute-Tests') {
steps {
catchError { // Handle error conditions in the event examples should be executed
executeTests()
}
}
post {
always {
junit testResults: '*.xml'
}
}
}
stage('Execute-Examples') {
when {
expression { env.CASSANDRA_VERSION == 'dse-6.8.30' }
}
steps {
executeExamples()
}
}
}
}
post {
aborted {
notifySlack('aborted')
}
success {
notifySlack('completed')
}
unstable {
notifySlack('unstable')
}
failure {
notifySlack('FAILED')
}
}
}
stage('Adhoc-Testing') {
when {
beforeAgent true
allOf {
expression { params.ADHOC_BUILD_TYPE == 'BUILD-AND-EXECUTE-TESTS' }
not { buildingTag() }
}
}
matrix {
axes {
axis {
name 'CASSANDRA_VERSION'
values '3.11', // Current Apache Cassandra
'4.0', // Development Apache Cassandra
'dse-5.1.35', // Legacy DataStax Enterprise
'dse-6.8.30' // Development DataStax Enterprise
}
axis {
name 'NODEJS_VERSION'
values '16', '18', '20'
}
}
when {
beforeAgent true
allOf {
expression { params.ADHOC_BUILD_AND_EXECUTE_TESTS_SERVER_VERSION ==~ /(ALL|${env.CASSANDRA_VERSION})/ }
expression { params.ADHOC_BUILD_AND_EXECUTE_TESTS_NODEJS_VERSION ==~ /(ALL|${env.NODEJS_VERSION})/ }
}
}
agent {
label "${OS_VERSION}"
}
stages {
stage('Describe-Build') {
steps {
describeAdhocTestingStage()
}
}
stage('Initialize-Environment') {
steps {
initializeEnvironment()
}
}
stage('Install-Driver-And-Dependencies') {
steps {
installDriverAndDependencies()
}
}
stage('Execute-Linter') {
steps {
executeLinter()
}
}
stage('Execute-Tests') {
steps {
catchError { // Handle error conditions in the event examples should be executed
executeTests()
}
}
post {
always {
junit testResults: '*.xml'
}
}
}
stage('Execute-Examples') {
when {
expression { params.ADHOC_BUILD_AND_EXECUTE_TESTS_EXECUTE_EXAMPLES }
}
steps {
executeExamples()
}
}
}
}
}
}
}