-
Notifications
You must be signed in to change notification settings - Fork 233
/
Jenkinsfile
537 lines (476 loc) · 18.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
#!groovy
def initializeEnvironment() {
env.DRIVER_DISPLAY_NAME = 'Cassandra C# Driver'
env.DRIVER_METRIC_TYPE = 'oss'
if (env.GIT_URL.contains('riptano/csharp-driver')) {
env.DRIVER_DISPLAY_NAME = 'private ' + env.DRIVER_DISPLAY_NAME
env.DRIVER_METRIC_TYPE = 'oss-private'
} else if (env.GIT_URL.contains('csharp-dse-driver')) {
env.DRIVER_DISPLAY_NAME = 'DSE C# 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}"
if (env.OS_VERSION.split('/')[0] == 'win') {
env.HOME = 'C:\\Users\\Admin'
env.HOME_WSL = '/mnt/c/Users/Admin'
powershell label: 'Copy SSL files', script: '''
wsl bash --login -c "cp -r $env:HOME_WSL/ccm/ssl `$HOME/ssl"
'''
powershell label: 'Download Apache Cassandra® or DataStax Enterprise', script: '''
rm $Env:HOME\\environment.txt
rm $Env:HOME\\driver-environment.ps1
wsl bash --login -c "$Env:CCM_ENVIRONMENT_SHELL_WINDOWS $Env:SERVER_VERSION"
wsl bash --login -c "cp ~/environment.txt $ENV:HOME_WSL"
$data = get-content "$Env:HOME\\environment.txt"
$data = $data -replace "`n","`r`n"
$newData = ""
$data | foreach {
$v1,$v2 = $_.split("=",2)
echo "1: $v1 2: $v2"
$newData += "`r`n`$Env:$v1='$v2'"
}
$newData += "`r`n`$Env:CASSANDRA_VERSION=`$Env:CCM_CASSANDRA_VERSION"
"$newData" | Out-File -filepath $Env:HOME\\driver-environment.ps1
'''
if (env.SERVER_VERSION.split('-')[0] == 'dse') {
powershell label: 'Update environment for DataStax Enterprise', script: '''
. $Env:HOME\\driver-environment.ps1
$newData = "`r`n`$Env:DSE_BRANCH=`"$Env:CCM_BRANCH`""
$newData += "`r`n`$Env:DSE_VERSION=`"$Env:CCM_VERSION`""
$newData += "`r`n`$Env:DSE_INITIAL_IPPREFIX=`"127.0.0.`""
$newData += "`r`n`$Env:DSE_IN_REMOTE_SERVER=`"false`""
"$newData" | Out-File -filepath $Env:HOME\\driver-environment.ps1 -append
'''
}
if (env.SERVER_VERSION == env.SERVER_VERSION_SNI_WINDOWS) {
powershell label: 'Update environment for SNI proxy tests', script: '''
$newData = "`r`n`$Env:SNI_ENABLED=`"true`""
$newData += "`r`n`$Env:SINGLE_ENDPOINT_PATH=`"$Env:HOME/proxy/run.ps1`""
$newData += "`r`n`$Env:SNI_CERTIFICATE_PATH=`"$Env:HOME/proxy/certs/client_key.pfx`""
$newData += "`r`n`$Env:SNI_CA_PATH=`"$Env:HOME/proxy/certs/root.crt`""
"$newData" | Out-File -filepath $Env:HOME\\driver-environment.ps1 -append
'''
}
powershell label: 'Set additional environment variables for windows tests', script: '''
$newData = "`r`n`$Env:PATH+=`";$env:JAVA_HOME\\bin`""
$newData += "`r`n`$Env:SIMULACRON_PATH=`"$Env:SIMULACRON_PATH_WINDOWS`""
$newData += "`r`n`$Env:CCM_USE_WSL=`"true`""
$newData += "`r`n`$Env:CCM_SSL_PATH=`"/root/ssl`""
"$newData" | Out-File -filepath $Env:HOME\\driver-environment.ps1 -append
'''
powershell label: 'Display .NET and environment information', script: '''
# Load CCM and driver configuration environment variables
cat $Env:HOME\\driver-environment.ps1
. $Env:HOME\\driver-environment.ps1
dotnet --version
gci env:* | sort-object name
'''
} else {
sh label: 'Download Apache Cassandra® or DataStax Enterprise', script: '''#!/bin/bash -le
. ${CCM_ENVIRONMENT_SHELL} ${SERVER_VERSION}
echo "CASSANDRA_VERSION=${CCM_CASSANDRA_VERSION}" >> ${HOME}/environment.txt
'''
//https://learn.microsoft.com/en-us/dotnet/core/compatibility/cryptography/5.0/default-cipher-suites-for-tls-on-linux
sh label: 'Setup custom openssl.cnf due to .NET 5+ TLS changes on Linux', script: '''#!/bin/bash -le
cat >> /home/jenkins/openssl.cnf << OPENSSL_EOF
openssl_conf = default_conf
[default_conf]
ssl_conf = ssl_sect
[ssl_sect]
system_default = system_default_sect
[system_default_sect]
MinProtocol = TLSv1
CipherString = @SECLEVEL=2:kEECDH:kRSA:kEDH:kPSK:kDHEPSK:kECDHEPSK:-aDSS:-3DES:!DES:!RC4:!RC2:!IDEA:-SEED:!eNULL:!aNULL:!MD5:-SHA384:-CAMELLIA:-ARIA:-AESCCM8
Ciphersuites = TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:TLS_AES_128_CCM_SHA256
OPENSSL_EOF
echo "OPENSSL_CONF=/home/jenkins/openssl.cnf" >> ${HOME}/environment.txt
'''
if (env.SERVER_VERSION.split('-')[0] == 'dse') {
env.DSE_FIXED_VERSION = env.SERVER_VERSION.split('-')[1]
sh label: 'Update environment for DataStax Enterprise', script: '''#!/bin/bash -le
rm ${HOME}/.ccm/config
cat > ${HOME}/.ccm/config << CONF_EOL
[repositories]
cassandra = https://repo.aws.dsinternal.org/artifactory/apache-mirror/cassandra
dse = http://repo-public.aws.dsinternal.org/tar/enterprise/dse-%s-bin.tar.gz
ddac = http://repo-public.aws.dsinternal.org/tar/enterprise/ddac-%s-bin.tar.gz
CONF_EOL
cat >> ${HOME}/environment.txt << ENVIRONMENT_EOF
CCM_PATH=${HOME}/ccm
DSE_INITIAL_IPPREFIX=127.0.0.
DSE_IN_REMOTE_SERVER=false
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_DISTRIBUTION=dse
CASSANDRA_VERSION=${DSE_FIXED_VERSION}
CCM_BRANCH=${DSE_FIXED_VERSION}
DSE_BRANCH=${DSE_FIXED_VERSION}
JDK=1.8
ENVIRONMENT_EOF
'''
}
if (env.SERVER_VERSION.split('-')[0] == 'hcd') {
env.HCD_FIXED_VERSION = env.SERVER_VERSION.split('-')[1]
sh label: 'Update environment for HCD', script: '''#!/bin/bash -le
cat >> ${HOME}/environment.txt << ENVIRONMENT_EOF
CCM_PATH=${HOME}/ccm
CCM_CASSANDRA_VERSION=${HCD_FIXED_VERSION} # maintain for backwards compatibility
CASSANDRA_VERSION=${HCD_FIXED_VERSION}
CCM_DISTRIBUTION=hcd
ENVIRONMENT_EOF
'''
}
if (env.SERVER_VERSION == env.SERVER_VERSION_SNI && env.DOTNET_VERSION != 'mono') {
sh label: 'Update environment for SNI proxy tests', script: '''#!/bin/bash -le
# Load CCM and driver configuration environment variables
set -o allexport
. ${HOME}/environment.txt
set +o allexport
cat >> ${HOME}/environment.txt << ENVIRONMENT_EOF
SNI_ENABLED=true
SINGLE_ENDPOINT_PATH=${HOME}/proxy/run.sh
SNI_CERTIFICATE_PATH=${HOME}/proxy/certs/client_key.pfx
SNI_CA_PATH=${HOME}/proxy/certs/root.crt
ENVIRONMENT_EOF
'''
}
sh label: 'Display .NET and environment information', script: '''#!/bin/bash -le
# Load CCM and driver configuration environment variables
set -o allexport
. ${HOME}/environment.txt
set +o allexport
if [ ${DOTNET_VERSION} = 'mono' ]; then
mono --version
else
dotnet --version
fi
printenv | sort
'''
}
}
def initializeEnvironmentStep() {
initializeEnvironment()
if (env.BUILD_STATED_SLACK_NOTIFIED != 'true') {
notifySlack()
}
}
def installDependencies() {
if (env.OS_VERSION.split('/')[0] == 'win') {
powershell label: 'Download saxon', script: '''
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
mkdir saxon
Invoke-WebRequest -OutFile saxon/saxon9he.jar -Uri https://repo1.maven.org/maven2/net/sf/saxon/Saxon-HE/9.8.0-12/Saxon-HE-9.8.0-12.jar
'''
} else {
sh label: 'Download saxon', script: '''#!/bin/bash -le
mkdir saxon
curl -L -o saxon/saxon9he.jar https://repo1.maven.org/maven2/net/sf/saxon/Saxon-HE/9.8.0-12/Saxon-HE-9.8.0-12.jar
'''
if (env.DOTNET_VERSION == 'mono') {
sh label: 'Install required packages for mono builds', script: '''#!/bin/bash -le
# Define alias for Nuget
nuget() {
mono /usr/local/bin/nuget.exe "$@"
}
export -f nuget
nuget install NUnit.Runners -Version 3.6.1 -OutputDirectory testrunner
'''
}
}
}
def buildDriver() {
if (env.OS_VERSION.split('/')[0] == 'win') {
powershell label: "Install required packages and build the driver for ${env.DOTNET_VERSION}", script: '''
dotnet restore src
dotnet restore src
'''
} else {
if (env.DOTNET_VERSION == 'mono') {
sh label: 'Build the driver for mono', script: '''#!/bin/bash -le
export BuildMonoOnly=True
export RunCodeAnalyzers=False
export MSBuildSDKsPath=/home/jenkins/dotnetcli/sdk/$(dotnet --version)/Sdks
msbuild /t:restore /v:m /p:RestoreDisableParallel=true src/Cassandra.sln || true
msbuild /t:restore /v:m /p:RestoreDisableParallel=true src/Cassandra.sln
msbuild /p:Configuration=Release /v:m /p:RestoreDisableParallel=true /p:DynamicConstants=LINUX src/Cassandra.sln || true
msbuild /p:Configuration=Release /v:m /p:RestoreDisableParallel=true /p:DynamicConstants=LINUX src/Cassandra.sln
'''
} else {
sh label: "Work around nuget issue", script: '''#!/bin/bash -le
mkdir -p /tmp/NuGetScratch
chmod -R ugo+rwx /tmp/NuGetScratch
'''
sh label: "Install required packages and build the driver for ${env.DOTNET_VERSION}", script: '''#!/bin/bash -le
dotnet restore src || true
dotnet restore src
'''
}
}
}
def executeTests(perCommitSchedule) {
if (perCommitSchedule) {
env.DOTNET_TEST_FILTER = "(TestCategory!=long)&(TestCategory!=memory)&(TestCategory!=realclusterlong)"
env.MONO_TEST_FILTER = "cat != long && cat != memory && cat != realclusterlong"
} else {
env.DOTNET_TEST_FILTER = "(TestCategory!=long)&(TestCategory!=memory)"
env.MONO_TEST_FILTER = "cat != long && cat != memory"
}
if (env.OS_VERSION.split('/')[0] == 'win') {
catchError {
powershell label: "Execute tests for ${env.DOTNET_VERSION}", script: '''
. $env:HOME\\Documents\\WindowsPowerShell\\Microsoft.PowerShell_profile.ps1
. $Env:HOME\\driver-environment.ps1
dotnet test src/Cassandra.IntegrationTests/Cassandra.IntegrationTests.csproj -v n -f $Env:DOTNET_VERSION -c Release --filter $Env:DOTNET_TEST_FILTER --logger "xunit;LogFilePath=../../TestResult_xunit.xml" -- RunConfiguration.TargetPlatform=x64
'''
}
powershell label: 'Convert the test results using saxon', script: '''
java -jar saxon/saxon9he.jar -o:TestResult.xml TestResult_xunit.xml tools/JUnitXml.xslt
'''
} else {
if (env.DOTNET_VERSION == 'mono') {
catchError {
sh label: 'Execute tests for mono', script: '''#!/bin/bash -le
# Load CCM and driver configuration 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
mono ./testrunner/NUnit.ConsoleRunner.3.6.1/tools/nunit3-console.exe src/Cassandra.IntegrationTests/bin/Release/net462/Cassandra.IntegrationTests.dll --where "$MONO_TEST_FILTER" --labels=All --result:"TestResult_nunit.xml"
'''
}
sh label: 'Convert the test results using saxon', script: '''#!/bin/bash -le
java -jar saxon/saxon9he.jar -o:TestResult.xml TestResult_nunit.xml tools/nunit3-junit.xslt
'''
} else {
catchError {
sh label: "Execute tests for ${env.DOTNET_VERSION}", script: '''#!/bin/bash -le
# Load CCM and driver configuration 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
export OPENSSL_CONF=/home/jenkins/openssl.cnf
dotnet test src/Cassandra.IntegrationTests/Cassandra.IntegrationTests.csproj -v n -f ${DOTNET_VERSION} -c Release --filter $DOTNET_TEST_FILTER --logger "xunit;LogFilePath=../../TestResult_xunit.xml"
'''
}
sh label: 'Convert the test results using saxon', script: '''#!/bin/bash -le
java -jar saxon/saxon9he.jar -o:TestResult.xml TestResult_xunit.xml tools/JUnitXml.xslt
'''
}
}
}
def notifySlack(status = 'started') {
// Set the global pipeline scoped environment (this is above each matrix)
env.BUILD_STATED_SLACK_NOTIFIED = 'true'
def osVersionDescription = 'Ubuntu'
if (params.CI_SCHEDULE_OS_VERSION == 'win/cs') {
osVersionDescription = 'Windows'
}
def buildType = 'Per-Commit'
def changeLogMsg = getFirstChangeLogEntry()
if (params.CI_SCHEDULE != 'DEFAULT-PER-COMMIT') {
buildType = "${params.CI_SCHEDULE.toLowerCase().capitalize()}-${osVersionDescription}"
}
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
} else if (status.equalsIgnoreCase("started")) {
color = '#fde93f' // Yellow
}
def message = """<${env.RUN_DISPLAY_URL}|Build ${env.DRIVER_DISPLAY_NAME} #${env.BUILD_NUMBER} - ${buildType}> ${status}
Commit <${env.GITHUB_COMMIT_URL}|${env.GIT_SHA}> on branch <${env.GITHUB_BRANCH_URL}|${env.BRANCH_NAME}>"""
if (!changeLogMsg.equalsIgnoreCase("")) {
message += """: _${changeLogMsg}_"""
}
if (!status.equalsIgnoreCase('Started')) {
message += """
${status} after ${currentBuild.durationString - ' and counting'}"""
}
slackSend color: "${color}",
channel: "#csharp-driver-dev-bots",
message: "${message}"
}
@NonCPS
def getChangeLog() {
def log = ""
def changeLogSets = currentBuild.changeSets
for (int i = 0; i < changeLogSets.size(); i++) {
def entries = changeLogSets[i].items
for (int j = 0; j < entries.length; j++) {
def entry = entries[j]
log += " * ${entry.msg} by ${entry.author} <br>"
}
}
return log;
}
@NonCPS
def getFirstChangeLogEntry() {
def changeLogSets = currentBuild.changeSets
def changeLogSetsSize = changeLogSets.size()
if (changeLogSets.size() > 0) {
def firstChangeLogSet = changeLogSets[changeLogSets.size() - 1]
def entries = firstChangeLogSet.items;
if (entries.length > 0) {
return entries[entries.length - 1].msg;
}
}
return "";
}
def describePerCommitStage() {
script {
currentBuild.displayName = "#${env.BUILD_NUMBER} - Per-Commit (${env.GIT_SHA})"
currentBuild.description = "Changelog:<br>${getChangeLog()}".take(250)
}
}
pipeline {
agent none
// Global pipeline timeout
options {
disableConcurrentBuilds(abortPrevious: true)
timeout(time: 10, unit: 'HOURS')
buildDiscarder(logRotator(artifactNumToKeepStr: '10', // Keep only the last 10 artifacts
numToKeepStr: '50')) // Keep only the last 50 build records
}
parameters {
choice(
name: 'CI_SCHEDULE',
choices: ['DEFAULT-PER-COMMIT'],
description: '')
choice(
name: 'CI_SCHEDULE_OS_VERSION',
choices: ['DEFAULT-PER-COMMIT'],
description: '')
}
environment {
DOTNET_CLI_TELEMETRY_OPTOUT = '1'
SERVER_VERSION_SNI = 'dse-6.7.17'
SERVER_VERSION_SNI_WINDOWS = '3.11'
SIMULACRON_PATH = '/home/jenkins/simulacron.jar'
SIMULACRON_PATH_WINDOWS = 'C:\\Users\\Admin\\simulacron.jar'
CCM_ENVIRONMENT_SHELL = '/usr/local/bin/ccm_environment.sh'
CCM_ENVIRONMENT_SHELL_WINDOWS = '/mnt/c/Users/Admin/ccm_environment.sh'
JABBA_SHELL = '/usr/lib/jabba/jabba.sh'
BuildAllTargets = 'True'
RunCodeAnalyzers = 'True'
}
stages {
stage('Per-Commit') {
when {
beforeAgent true
allOf {
expression { params.CI_SCHEDULE == 'DEFAULT-PER-COMMIT' }
not { buildingTag() }
}
}
environment {
OS_VERSION = 'ubuntu/bionic64/csharp-driver'
}
matrix {
axes {
axis {
name 'SERVER_VERSION'
values '3.11', // latest 3.11.x Apache Cassandra�
'4.1', // latest 4.x Apache Cassandra�
'5.0', // Development Apache Cassandra�
'dse-5.1.35', // latest 5.1.x DataStax Enterprise
'dse-6.8.30', // latest 6.7.x DataStax Enterprise
'dse-6.9.3', // latest DataStax Enterprise
'hcd-1.0.0' // Hyper-Converged Database
}
axis {
name 'DOTNET_VERSION'
values 'mono', 'net8', 'net6'
}
}
excludes {
exclude {
axis {
name 'DOTNET_VERSION'
values 'mono'
}
axis {
name 'SERVER_VERSION'
values '3.11', '4.1', 'dse-5.1.35', 'dse-6.8.30'
}
}
exclude {
axis {
name 'DOTNET_VERSION'
values 'net8'
}
axis {
name 'SERVER_VERSION'
values '3.11', '5.0', 'dse-6.9.3', 'hcd-1.0.0'
}
}
}
agent {
label "${OS_VERSION}"
}
stages {
stage('Initialize-Environment') {
steps {
initializeEnvironmentStep()
}
}
stage('Describe-Build') {
steps {
describePerCommitStage()
}
}
stage('Install-Dependencies') {
steps {
installDependencies()
}
}
stage('Build-Driver') {
steps {
buildDriver()
}
}
stage('Execute-Tests') {
steps {
executeTests(true)
}
post {
always {
junit testResults: '**/TestResult.xml'
}
}
}
}
}
post {
aborted {
notifySlack('aborted')
}
success {
notifySlack('completed')
}
unstable {
notifySlack('unstable')
}
failure {
notifySlack('FAILED')
}
}
}
}
}