Repository navigation
Expand file tree
/
Copy pathJenkinsfile.split
More file actions
701 lines (662 loc) · 37.5 KB
/
Copy pathJenkinsfile.split
File metadata and controls
701 lines (662 loc) · 37.5 KB
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
// The GIT repository for this pipeline lib is defined in the global Jenkins setting
@Library('jenkins-pipeline-library')
import com.gentics.*
// Make the helpers aware of this jobs environment
JobContext.set(this)
properties([
parameters([
booleanParam(name: 'checkGitCommit', defaultValue: false, description: 'If set to true, the current git revision is compared with the git revision of the last successful build. If they are equal, the build is skipped and env.BUILD_SKIPPED is set to true'),
booleanParam(name: 'runTests', defaultValue: true, description: "Whether to run the unit tests"),
booleanParam(name: 'testHsqlm', defaultValue: true , description: "Whether to test HSQLDB In-Memory context"),
booleanParam(name: 'testMaria', defaultValue: false, description: "Whether to test OSS MariaDB context"),
booleanParam(name: 'testMssql', defaultValue: false, description: "Whether to test Enterprise MS SQL context"),
booleanParam(name: 'testOracle', defaultValue: false, description: "Whether to test Enterprise Oracle XE context"),
booleanParam(name: 'testPostgres', defaultValue: false, description: "Whether to test Enterprise PostgreSQL context"),
booleanParam(name: 'runDeploy', defaultValue: false, description: "Whether to run the deploy steps."),
booleanParam(name: 'runDeployTesting', defaultValue: false, description: "Whether to run the testing deploy steps."),
booleanParam(name: 'runDocker', defaultValue: false, description: "Whether to run the docker steps."),
booleanParam(name: 'runMavenBuild', defaultValue: false, description: "Whether to run the maven build steps."),
booleanParam(name: 'runHelmBuild', defaultValue: false, description: "Whether to run the helm build steps."),
booleanParam(name: 'setBranchAsVersion', defaultValue: false, description: "Whether to set the branch name as project version (unless runDeploy is true). Use this together with runMavenBuild to install the maven artifacts to the local repository (changelog and documentation will be skipped)."),
booleanParam(name: 'dontSplitTests', defaultValue: false, description: "Whether to run tests in a single in-place chunk instead of delegating to the evenly distributed splits"),
booleanParam(name: 'skipMeshTests', defaultValue: false, description: "Whether to skip unit tests for Mesh"),
booleanParam(name: 'skipPluginTests', defaultValue: false, description: "Whether to skip unit tests for Mesh Plugins"),
booleanParam(name: 'skipSearchTests', defaultValue: false, description: "Whether to skip search tests or not"),
booleanParam(name: 'runSonar', defaultValue: false, description: "Whether to run the sonarqube checks"),
booleanParam(name: 'runSmokeTests', defaultValue: false, description: "Whether to run smoke tests for the selected databases"),
booleanParam(name: 'runUnstableTests', defaultValue: false, description: "Whether to run tests in failing group."),
booleanParam(name: 'runClusterTests', defaultValue: false, description: "Whether to run cluster tests."),
booleanParam(name: 'useOpenApiTestClient',defaultValue: false, description: "Whether to use an autogenerated OpenAPI OkHTTP 3 based REST client for the tests."),
booleanParam(name: 'consistencyChecks', defaultValue: false, description: "Whether to do consistency checks for every test. Enabling this will increase overall test runtime."),
booleanParam(name: 'omitScan', defaultValue: false, description: "Omit scanning the docker images and plugins"),
booleanParam(name: 'skipJsLibraries', defaultValue: false, description: "Whether to skip deployment of Javascript/Typescript libraries"),
booleanParam(name: 'forceJsDeploy', defaultValue: false, description: "Whether to deploy the JS artifacts specifically. When 'runDeploy' is true, then already does deployment - Only considered if 'skipJsLibraries' is false, and when 'runDeployTesting' is true."),
string( name: 'testingVersion', defaultValue: "", description: "Version for testing"),
string( name: 'meshVersion', defaultValue: "", description: "Override Mesh version"),
string( name: 'meshJsVersion', defaultValue: "", description: "Override Mesh JS version for the testing deployment"),
booleanParam(name: 'debug', defaultValue: false, description: "Debug output."),
])
])
final def gitCommitTag = '[Jenkins | ' + env.JOB_BASE_NAME + ']';
final def splits = 20;
final def runs = 20;
final def registryHostStaging = "push.docker.gentics.com/docker-products";
final def registryHostTest = "push.docker.gentics.com/docker-snapshots";
final def helmRepositoryProd = 'https://repo.gentics.com/repository/helm/';
final def helmRepositoryTest = 'https://repo.gentics.com/repository/helm-snapshots/';
def registryHost = registryHostStaging;
def helmRepository = helmRepositoryProd;
def meshOssVersion = '';
def helmVersion = null;
def pluginModules = [':mesh-commercial-plugins-common', ':mesh-commercial-plugins-test-common', ':mesh-comment-plugin', ':mesh-export-plugin', ':mesh-forms-plugin', ':mesh-gcms-plugin', ':mesh-like-plugin', ':mesh-mustread-plugin', ':mesh-favorite-plugin', ':mesh-keycloak-plugin', ':mesh-search-plugin']
final def testPart(partName, current, branches) {
def partId = "split${partName}${current}"
branches[partId] = {
node('mesh-worker-3.2') {
echo "Preparing slave environment for ${partId}"
sh "rm -rf ${partId}"
sh "mkdir ${partId}"
dir(partId) {
unstash 'project'
def postfix = current;
if (current <= 9) {
postfix = "0" + current
}
sshagent(["git"]) {
try {
def jacoco = Boolean.valueOf(params.runSonar);
def noMariadb = true
def noMssql = true
def noOracle = true
def noPostgres = true
def noHsqldb = true
if (Boolean.valueOf(params.testMssql)) {
noMssql = false
}
if (Boolean.valueOf(params.testOracle)) {
noOracle = false
}
if (Boolean.valueOf(params.testPostgres)) {
noPostgres = false
}
if (Boolean.valueOf(params.testMaria)) {
noMariadb = false
}
if (Boolean.valueOf(params.testHsqlm)) {
noHsqldb = false
}
withCredentials([
usernamePassword(credentialsId: 'docker.gentics.com', usernameVariable: 'repoUsername', passwordVariable: 'repoPassword'),
usernamePassword(credentialsId: 'gentics.gpg', usernameVariable: 'gpgKeyName', passwordVariable: 'gpgKeyPass')
]) {
try {
// prior to starting the tests, start the docker containers with the db and the testdb-manager
sh 'docker login -u $repoUsername -p $repoPassword docker.gentics.com'
if (!noMariadb) {
sh "mvn -pl :mesh-database-connector-mariadb docker:start -Dskip.mariadb.tests=${noMariadb} "
}
if (!noMssql) {
sh "mvn -pl :mesh-enterprise-database-connector-mssql docker:start -Dskip.mssql.tests=${noMssql}"
}
if (!noOracle) {
sh "mvn -pl :mesh-enterprise-database-connector-oracle docker:start -Dskip.oracle.tests=${noOracle}"
}
if (!noPostgres) {
sh "mvn -pl :mesh-enterprise-database-connector-postgres docker:start -Dskip.postgres.tests=${noPostgres}"
}
if (!noHsqldb || !noMssql || !noOracle || !noPostgres || !noMariadb) {
// run Mesh tests
withEnv(["TESTCONTAINERS_RYUK_DISABLED=true", "MESH_CONSISTENCY_CHECKS=" + (Boolean.valueOf(params.consistencyChecks) ? "true" : "false"), "MAVEN_OPTS=-Xmx1g -XX:MaxMetaspaceSize=128m ", "MESH_REST_CLIENT_CLASS=" + (Boolean.valueOf(params.useOpenApiTestClient) ? "com.gentics.mesh.test.openapi.OpenAPIMeshRestClient" : "")]) {
sh ".jenkins/run-splits.sh includes-${postfix} ${jacoco} ${partName} ${partId}"
}
} else {
echo "No database chosen for the tests!"
}
} finally {
// finally stop the docker containers
if (!noMariadb) {
sh "mvn -pl :mesh-database-connector-mariadb docker:stop -Dskip.mariadb.tests=${noMariadb} "
}
if (!noMssql) {
sh "mvn -pl :mesh-enterprise-database-connector-mssql docker:stop -Dskip.mssql.tests=${noMssql}"
}
if (!noOracle) {
sh "mvn -pl :mesh-enterprise-database-connector-oracle docker:stop -Dskip.oracle.tests=${noOracle}"
}
if (!noPostgres) {
sh "mvn -pl :mesh-enterprise-database-connector-postgres docker:stop -Dskip.postgres.tests=${noPostgres}"
}
}
}
stash name: "jacoco" + current, includes: "**/jacoco-partial.exec", allowEmpty: true
} finally {
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/*.xml'])
deleteDir()
}
}
}
}
}
}
stage("Setup Build Environment") {
node("mesh-root-worker-3.3") {
githubBuildStarted()
try {
stage("Checkout") {
scm_variables = checkout scm
env.GIT_COMMIT = scm_variables.get('GIT_COMMIT')
env.GIT_PREVIOUS_SUCCESSFUL_COMMIT = scm_variables.get('GIT_PREVIOUS_SUCCESSFUL_COMMIT')
}
def branchName = GitHelper.fetchCurrentBranchName()
def version = MavenHelper.getVersion()
helmVersion = version;
if( Boolean.valueOf(params.runDeployTesting) ){
//helm version need a semantic version ci-devtest is not valid - prefix test versions with 0-
helmVersion = "0-${helmVersion}"
}
stage('Check git commit') {
if ( Boolean.valueOf(params.checkGitCommit) ) {
if ( env.GIT_COMMIT == env.GIT_PREVIOUS_SUCCESSFUL_COMMIT ) {
echo "env.GIT_COMMIT (" + env.GIT_COMMIT + ") = env.GIT_PREVIOUS_SUCCESSFUL_COMMIT (" + env.GIT_PREVIOUS_SUCCESSFUL_COMMIT + "). Skip building."
env.BUILD_SKIPPED = "true"
} else {
echo "env.GIT_COMMIT (" + env.GIT_COMMIT + ") != env.GIT_PREVIOUS_SUCCESSFUL_COMMIT (" + env.GIT_PREVIOUS_SUCCESSFUL_COMMIT + "). Need to rebuild."
}
} else {
echo "Not checking git commit"
}
}
stage("Set Version") {
withCredentials([usernamePassword(credentialsId: 'docker.gentics.com', usernameVariable: 'repoUsername', passwordVariable: 'repoPassword')]) {
if (Boolean.valueOf(params.runDeploy)) {
if (version) {
echo "Building version " + version
version = MavenHelper.transformSnapshotToReleaseVersion(version)
MavenHelper.setVersion(version)
helmVersion = version;
}
sh 'git add **/pom.xml'
// Committing the changes is done later in git-push, as the JS packages also need to update their versions
} else if (Boolean.valueOf(params.setBranchAsVersion)) {
version = branchName + "-SNAPSHOT"
echo "Building version " + version
MavenHelper.setVersion(version)
}
if (params.testingVersion?.trim()) {
version = params.testingVersion.trim()
echo "Building version test build with name: " + version
MavenHelper.setVersion(version)
}
}
}
stage("Setup") {
if (params.meshVersion?.trim()) {
withCredentials([usernamePassword(credentialsId: 'docker.gentics.com', usernameVariable: 'repoUsername', passwordVariable: 'repoPassword')]) {
echo "Setting Gentics Mesh version to " + params.meshVersion.trim()
MavenHelper.setProperty("mesh.version", params.meshVersion.trim())
}
}
}
stage("Prebuild") {
if (env.BUILD_SKIPPED != "true" && (Boolean.valueOf(params.runTests) || Boolean.valueOf(params.runUnstableTests) )) {
def extraFlags = ""
if (Boolean.valueOf(params.runSonar)) {
extraFlags += " -Djacoco.skip=false"
}
// Install is needed to provide deps for the test plugin build
// echo "Setup of GPG"
// sh "gpg --no-tty --batch --import /mnt/credentials/gpg/gpg-public-key.asc"
// sh "gpg --no-tty --batch --import /mnt/credentials/gpg/gpg-secret-key.asc"
withCredentials([usernamePassword(credentialsId: 'docker.gentics.com', usernameVariable: 'repoUsername', passwordVariable: 'repoPassword'),usernamePassword(credentialsId: 'gentics.gpg', usernameVariable: 'gpgKeyName', passwordVariable: 'gpgKeyPass')]) {
sh "mvn -s build/settings.xml -ff -B -U -pl '!changelog,!doc' -Dmaven.javadoc.skip=true -Dskip.test-plugins=false -Dskip.cluster.tests=true -Dgpg.skip=false -DskipTests ${extraFlags} clean install"
}
} else {
echo "Omitted since we don't execute tests"
}
}
stage("Test") {
def debug = ""
if (Boolean.valueOf(params.debug)) {
debug = "debug"
}
if (env.BUILD_SKIPPED != "true" && Boolean.valueOf(params.runTests)) {
if (!Boolean.valueOf(params.skipMeshTests)) {
if (!Boolean.valueOf(params.dontSplitTests)) {
if (Boolean.valueOf(params.skipSearchTests)) {
sh ".jenkins/split-tests.sh ${splits} nosearch"
} else {
sh ".jenkins/split-tests.sh ${splits}"
}
stash includes: '**', name: 'project'
def branches = [:]
for (int i = 0; i < runs; i++) {
def current = i
if (Boolean.valueOf(params.testMaria)) {
echo "MariaDB split.."
testPart("mariadb", current, branches)
}
if (Boolean.valueOf(params.testHsqlm)) {
echo "HSQLDB split.."
testPart("hsqlm", current, branches)
}
if (Boolean.valueOf(params.testMssql)) {
echo "MSSQL split.."
testPart("mssql", current, branches)
}
if (Boolean.valueOf(params.testOracle)) {
echo "Oracle split.."
testPart("oracle", current, branches)
}
if (Boolean.valueOf(params.testPostgres)) {
echo "Postgres split.."
testPart("postgres", current, branches)
}
}
try {
parallel branches
} catch (err) {
echo "Failed " + err.getMessage()
error err.getMessage()
}
} else {
sshagent(["git"]) {
def noMariadb = true
def noHsqldb = true
def noMssql = true
def noOracle = true
def noPostgres = true
if (Boolean.valueOf(params.testMssql)) {
noMssql = false
} else {
echo "MS SQL skipped.."
}
if (Boolean.valueOf(params.testOracle)) {
noOracle = false
} else {
echo "Oracle XE skipped.."
}
if (Boolean.valueOf(params.testPostgres)) {
noPostgres = false
} else {
echo "Postgres skipped.."
}
if (Boolean.valueOf(params.testMaria)) {
noMariadb = false
} else {
echo "MariaDB skipped.."
}
if (Boolean.valueOf(params.testHsqlm)) {
noHsqldb = false
} else {
echo "HSQLDB skipped.."
}
try {
withCredentials([usernamePassword(credentialsId: 'docker.gentics.com', usernameVariable: 'repoUsername', passwordVariable: 'repoPassword'),usernamePassword(credentialsId: 'gentics.gpg', usernameVariable: 'gpgKeyName', passwordVariable: 'gpgKeyPass')]) {
withEnv(["TESTCONTAINERS_RYUK_DISABLED=true","MESH_CONSISTENCY_CHECKS=" + (Boolean.valueOf(params.consistencyChecks) ? "true" : "false"), "MESH_REST_CLIENT_CLASS=" + (Boolean.valueOf(params.useOpenApiTestClient) ? "com.gentics.mesh.test.openapi.OpenAPIMeshRestClient" : "")]) {
sh "mvn -fae -Dsurefire.excludedGroups=com.gentics.mesh.test.category.FailingTests,com.gentics.mesh.test.category.ClusterTests -Dmaven.javadoc.skip=true -Dskip.cluster.tests=true -Dmaven.test.failure.ignore=true -Dmesh.container.image.prefix=docker.gentics.com/ -Dskip.mssql.tests=${noMssql} -Dskip.oracle.tests=${noOracle} -Dskip.postgres.tests=${noPostgres} -Dskip.mariadb.tests=${noMariadb} -Dskip.hsqlmemory.tests=${noHsqldb} -pl '!" + pluginModules.join(",!") + "' -B -U -e test"
}
}
} finally {
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/*.xml'])
}
}
}
}
// run plugin tests
if (!Boolean.valueOf(params.skipPluginTests)) {
try {
withCredentials([usernamePassword(credentialsId: 'docker.gentics.com', usernameVariable: 'repoUsername', passwordVariable: 'repoPassword')]) {
sh 'docker login -u $repoUsername -p $repoPassword docker.gentics.com'
withEnv(["TESTCONTAINERS_RYUK_DISABLED=true", "MESH_CONSISTENCY_CHECKS=" + (Boolean.valueOf(params.consistencyChecks) ? "true" : "false"), "MAVEN_OPTS=-Xmx1g -XX:MaxMetaspaceSize=128m ", "MESH_REST_CLIENT_CLASS=" + (Boolean.valueOf(params.useOpenApiTestClient) ? "com.gentics.mesh.test.openapi.OpenAPIMeshRestClient" : "")]) {
sh "mvn -fae -B -Dmaven.test.failure.ignore=true -pl '" + pluginModules.join(",") + "' test"
}
}
} finally {
step([$class: 'JUnitResultArchiver', testResults: 'plugins/**/target/surefire-reports/*.xml,ee/plugins/**/target/surefire-reports/*.xml'])
}
}
} else {
echo "Tests skipped.."
}
}
stage("Javascript Packages") {
if (env.BUILD_SKIPPED != "true" && !Boolean.valueOf(params.skipJsLibraries)) {
environment {
// Disable colors/special characters, if projects do properly check it
TERM="dumb"
// Disable node based color libraries
FORCE_COLOR="0"
// Mark this as a CI build
CI="true"
}
dir("js") {
// Patch test version, if requested
def jsVersion = version
if (params.meshJsVersion?.trim()) {
jsVersion = params.meshJsVersion.trim()
}
// Install dependencies
sh 'npm ci --no-audit --no-fund'
if (
// If the version isn't semver, we can't set it, as NX just explodes
(jsVersion ==~ /[\d]+\.[\d]+\.[\d]+[a-zA-Z0-9-]*/)
// Or if we just do a testing deployment
|| !Boolean.valueOf(params.runDeployTesting)
) {
// Set the version for the packages
sh "npm run nx -- release version ${jsVersion}"
}
// Build all JS packages
sh 'npm run nx -- run-many --targets=build --configuration=ci'
// Run the tests if enabled
if (Boolean.valueOf(params.runTests)) {
sh 'npm run nx -- run-many --targets=test --configuration=ci'
}
}
} else {
echo "Javascript Packages skipped.."
}
}
stage("Unstable Tests") {
if (env.BUILD_SKIPPED != "true" && Boolean.valueOf(params.runUnstableTests)) {
sshagent(["git"]) {
try {
withCredentials([usernamePassword(credentialsId: 'docker.gentics.com', usernameVariable: 'repoUsername', passwordVariable: 'repoPassword'),usernamePassword(credentialsId: 'gentics.gpg', usernameVariable: 'gpgKeyName', passwordVariable: 'gpgKeyPass')]) {
withEnv(["TESTCONTAINERS_RYUK_DISABLED=true", "MESH_CONSISTENCY_CHECKS=" + (Boolean.valueOf(params.consistencyChecks) ? "true" : "false")]) {
sh "mvn -fae -Dsurefire.groups=com.gentics.mesh.test.category.FailingTests -Dmaven.javadoc.skip=true -Dskip.cluster.tests=true -Dmaven.test.failure.ignore=true -Dmesh.container.image.prefix=docker.gentics.com/ -B -e -pl '!doc,!" + pluginModules.join(",!") + "' test -DfailIfNoTests=false"
}
}
} finally {
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/*.xml'])
}
}
} else {
echo "Failing test group execution skipped.."
}
}
stage("Smoke Tests") {
if (env.BUILD_SKIPPED != "true" && Boolean.valueOf(params.runSmokeTests)) {
sshagent(["git"]) {
// Run smoke tests across all production databases
def noMariadb = false
def noMssql = false
def noOracle = false
def noPostgres = false
def noHsqlm = true
withCredentials([
usernamePassword(credentialsId: 'docker.gentics.com', usernameVariable: 'repoUsername', passwordVariable: 'repoPassword'),
usernamePassword(credentialsId: 'gentics.gpg', usernameVariable: 'gpgKeyName', passwordVariable: 'gpgKeyPass')
]) {
try {
sh 'docker login -u $repoUsername -p $repoPassword docker.gentics.com'
if (!noMssql) {
sh "mvn -pl :mesh-enterprise-database-connector-mssql docker:start -Dskip.mssql.tests=${noMssql}"
echo "Running MSSql smoke test"
sh "mvn -fae -Dmaven.javadoc.skip=true -Dskip.cluster.tests=true -Dmaven.test.failure.ignore=true -Dmesh.container.image.prefix=docker.gentics.com/ -B -e -pl '!doc' -Dskip.mssql.tests=false -Dmesh.testdb.manager.host=localhost -Dmesh.testdb.manager.port=8080 -Dtest=com.gentics.mesh.smoketests.SmokeTest -DfailIfNoTests=false test"
}
if (!noOracle) {
sh "mvn -pl :mesh-enterprise-database-connector-oracle docker:start -Dskip.oracle.tests=${noOracle}"
echo "Running Oracle smoke test"
sh "mvn -fae -Dmaven.javadoc.skip=true -Dskip.cluster.tests=true -Dmaven.test.failure.ignore=true -Dmesh.container.image.prefix=docker.gentics.com/ -B -e -pl '!doc' -Dskip.oracle.tests=false -Dmesh.testdb.manager.host=localhost -Dmesh.testdb.manager.port=8080 -Dtest=com.gentics.mesh.smoketests.SmokeTest -DfailIfNoTests=false test"
}
if (!noPostgres) {
sh "mvn -pl :mesh-enterprise-database-connector-postgres docker:start -Dskip.postgres.tests=${noPostgres}"
echo "Running Postgres smoke test"
sh "mvn -fae -Dmaven.javadoc.skip=true -Dskip.cluster.tests=true -Dmaven.test.failure.ignore=true -Dmesh.container.image.prefix=docker.gentics.com/ -B -e -pl '!doc' -Dskip.postgres.tests=false -Dmesh.testdb.manager.host=localhost -Dmesh.testdb.manager.port=8080 -Dtest=com.gentics.mesh.smoketests.SmokeTest -DfailIfNoTests=false test"
}
if (!noMariadb) {
sh "mvn -pl :mesh-database-connector-mariadb docker:start -Dskip.mariadb.tests=${noMariadb} "
echo "Running MariaDB smoke test"
sh "mvn -fae -Dmaven.javadoc.skip=true -Dskip.cluster.tests=true -Dmaven.test.failure.ignore=true -Dmesh.container.image.prefix=docker.gentics.com/ -B -e -pl '!doc' -Dskip.mariadb.tests=false -Dmesh.testdb.manager.host=localhost -Dmesh.testdb.manager.port=8080 -Dtest=com.gentics.mesh.smoketests.SmokeTest -DfailIfNoTests=false test"
}
} finally {
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/*.xml'])
// stop the db manager
if (!noMariadb) {
sh "mvn -pl :mesh-database-connector-mariadb docker:stop -Dskip.mariadb.tests=${noMariadb} "
}
if (!noMssql) {
sh "mvn -pl :mesh-enterprise-database-connector-mssql docker:stop -Dskip.mssql.tests=${noMssql}"
}
if (!noOracle) {
sh "mvn -pl :mesh-enterprise-database-connector-oracle docker:stop -Dskip.oracle.tests=${noOracle}"
}
if (!noPostgres) {
sh "mvn -pl :mesh-enterprise-database-connector-postgres docker:stop -Dskip.postgres.tests=${noPostgres}"
}
}
}
}
} else {
echo "Smoke tests skipped.."
}
}
stage("Maven Build") {
if (env.BUILD_SKIPPED != "true" && Boolean.valueOf(params.runMavenBuild)) {
sshagent(["git"]) {
if (Boolean.valueOf(params.runDeployTesting)) {
// echo "Setup of GPG"
// sh "gpg --no-tty --batch --import /mnt/credentials/gpg/gpg-public-key.asc"
// sh "gpg --no-tty --batch --import /mnt/credentials/gpg/gpg-secret-key.asc"
withCredentials([
usernamePassword(credentialsId: 'docker.gentics.com', usernameVariable: 'repoUsername', passwordVariable: 'repoPassword'),
usernamePassword(credentialsId: 'gentics.gpg', usernameVariable: 'gpgKeyName', passwordVariable: 'gpgKeyPass')
]) {
sh "mvn -B -DskipTests -Dskip.unit.tests -am -pl 'server,mcp-server,content-rag,content-rag/rag-service,:mesh-database-connector-mariadb,:mesh-database-connector-hsqldb,:mesh-enterprise-database-connector-mssql,:mesh-enterprise-database-connector-oracle,:mesh-enterprise-database-connector-postgres,bom,plugin-bom,plugin-parent,:mesh-forms-plugin,:mesh-comment-plugin,:mesh-export-plugin,:mesh-gcms-plugin,:mesh-like-plugin,:mesh-mustread-plugin,:mesh-favorite-plugin,:mesh-keycloak-plugin,:mesh-search-plugin' clean deploy"
}
} else if (Boolean.valueOf(params.runDeploy)) {
// echo "Setup of GPG"
// sh "gpg --no-tty --batch --import /mnt/credentials/gpg/gpg-public-key.asc"
// sh "gpg --no-tty --batch --import /mnt/credentials/gpg/gpg-secret-key.asc"
withCredentials([
usernamePassword(credentialsId: 'docker.gentics.com', usernameVariable: 'repoUsername', passwordVariable: 'repoPassword'),
usernamePassword(credentialsId: 'gentics.gpg', usernameVariable: 'gpgKeyName', passwordVariable: 'gpgKeyPass')
]) {
sh "mvn -U -B -DskipTests -Dgpg.skip=false clean deploy"
}
} else if (Boolean.valueOf(params.setBranchAsVersion)) {
withCredentials([
usernamePassword(credentialsId: 'docker.gentics.com', usernameVariable: 'repoUsername',
passwordVariable: 'repoPassword'),usernamePassword(credentialsId: 'gentics.gpg', usernameVariable: 'gpgKeyName', passwordVariable: 'gpgKeyPass')
]) {
sh "mvn -U -B -DskipTests -Dgpg.skip=false -pl '!doc,!changelog' clean install"
}
} else {
withCredentials([
usernamePassword(credentialsId: 'docker.gentics.com', usernameVariable: 'repoUsername', passwordVariable: 'repoPassword'),
usernamePassword(credentialsId: 'gentics.gpg', usernameVariable: 'gpgKeyName', passwordVariable: 'gpgKeyPass')
]) {
sh "mvn -B -DskipTests clean package"
}
}
}
} else {
echo "Maven build skipped.."
}
}
stage("Plugin Scan") {
// plugin jars are built by the prebuild (tests) or by the maven build (except the testing deployment, which omits the plugins)
def pluginsBuilt = Boolean.valueOf(params.runTests) || Boolean.valueOf(params.runUnstableTests) || (Boolean.valueOf(params.runMavenBuild) && !Boolean.valueOf(params.runDeployTesting))
if (env.BUILD_SKIPPED != "true" && !params.omitScan && pluginsBuilt) {
scanRootFilesystem path: "${env.WORKSPACE}/plugins", exitCode: 1, offline: true
scanRootFilesystem path: "${env.WORKSPACE}/ee/plugins", exitCode: 1, offline: true
} else {
echo "Plugin scan skipped.."
}
}
stage ("Sonar") {
if (env.BUILD_SKIPPED != "true" && Boolean.valueOf(params.runTests) && Boolean.valueOf(params.runSonar)) {
if (!Boolean.valueOf(params.dontSplitTests)) {
for (int i = 0; i < runs; i++) {
echo "Invoking merge for " + i
unstash "jacoco" + i
sh "mvn jacoco:merge@merge-all-jacoco -Djacoco.skip.merge=false"
sh "find -name jacoco-partial.exec -exec rm {} \\;"
}
}
withCredentials([string(credentialsId: 'sonarcloud.key', variable: 'TOKEN')]) {
sh "mvn sonar:sonar -Dsonar.projectKey=gentics_mesh -Dsonar.organization=gentics -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$TOKEN -Dsonar.pullrequest.key=$GITHUB_PR_NUMBER -Dsonar.pullrequest.branch=" + branchName + " -Dsonar.pullrequest.base=dev"
}
}
}
stage("Cluster Tests") {
if (env.BUILD_SKIPPED != "true" && Boolean.valueOf(params.runClusterTests)) {
stash includes: '**', name: 'project'
node("mesh-cluster-worker-17") {
try {
unstash 'project'
sh "mvn -B -DskipTests clean install"
sh "mvn -B -Dsurefire.groups=com.gentics.mesh.test.category.ClusterTests -DfailIfNoTests=false -Dmesh.container.image.prefix=docker.gentics.com/ test"
} finally {
step([$class: 'JUnitResultArchiver', testResults: 'distributed/target/surefire-reports/*.xml'])
deleteDir()
}
}
} else {
echo "Cluster tests skipped.."
}
}
stage("Docker Build") {
if (env.BUILD_SKIPPED != "true" && Boolean.valueOf(params.runDocker)) {
if (Boolean.valueOf(params.runDeployTesting)) {
registryHost = registryHostTest;
}
// server
sh "rm server/target/*sources.jar || true"
sh "rm server/target/*javadoc.jar || true"
sh "cd server ; docker build --network=host -t " + registryHost + "/gentics/mesh:latest -t " + registryHost + "/gentics/mesh:" + version + " . ; cd .. "
sh "cd mcp-server ; docker build --network=host -t " + registryHost + "/gentics/mesh/mcp-server:latest -t " + registryHost + "/gentics/mesh/mcp-server:" + version + " --build-arg VERSION=" + version + " . ; cd .."
sh "cd content-rag/rag-service ; docker build --network=host -t " + registryHost + "/gentics/mesh/content-rag:latest -t " + registryHost + "/gentics/mesh/content-rag:" + version + " --build-arg VERSION=" + version + " . ; cd ../.."
if (!params.omitScan) {
scanImage image: registryHost + "/gentics/mesh:" + version, exitCode: 1, dockerParams: "-v ${env.WORKSPACE}/build/trivyignore:/tmp/trivyignore", params: "--ignorefile /tmp/trivyignore"
scanImage image: registryHost + "/gentics/mesh/mcp-server:" + version, exitCode: 1, dockerParams: "-v ${env.WORKSPACE}/build/trivyignore:/tmp/trivyignore", params: "--ignorefile /tmp/trivyignore"
scanImage image: registryHost + "/gentics/mesh/content-rag:" + version, exitCode: 1, dockerParams: "-v ${env.WORKSPACE}/build/trivyignore:/tmp/trivyignore", params: "--ignorefile /tmp/trivyignore"
}
// connectors
def mavenVersion = MavenHelper.getVersion()
sh "cd .docker ; cp ../connectors/hsqldb/target/mesh-database-connector-hsqldb-" + mavenVersion + ".jar ./mesh-connector.jar ; docker build --network=host -t " + registryHost + "/gentics/mesh-hsqldb:latest -t " + registryHost + "/gentics/mesh-hsqldb:" + version + " --build-arg MESH_VERSION=" + version + " --build-arg MESH_REGISTRY_HOST=" + registryHost + " . ; rm -f mesh-connector.jar ; cd .."
sh "cd .docker ; cp ../connectors/mariadb/target/mesh-database-connector-mariadb-" + mavenVersion + ".jar ./mesh-connector.jar ; docker build --network=host -t " + registryHost + "/gentics/mesh-mariadb:latest -t " + registryHost + "/gentics/mesh-mariadb:" + version + " --build-arg MESH_VERSION=" + version + " --build-arg MESH_REGISTRY_HOST=" + registryHost + " . ; rm -f mesh-connector.jar ; cd .."
sh "cd .docker ; cp ../ee/connectors/postgres/target/mesh-enterprise-database-connector-postgres-" + mavenVersion + ".jar ./mesh-connector.jar ; docker build --network=host -t " + registryHost + "/gentics/mesh-enterprise-postgres:latest -t " + registryHost + "/gentics/mesh-enterprise-postgres:" + version + " --build-arg MESH_VERSION=" + version + " --build-arg MESH_REGISTRY_HOST=" + registryHost + " . ; rm -f mesh-connector.jar ; cd .."
sh "cd .docker ; cp ../ee/connectors/mssql/target/mesh-enterprise-database-connector-mssql-" + mavenVersion + ".jar ./mesh-connector.jar ; docker build --network=host -t " + registryHost + "/gentics/mesh-enterprise-mssql:latest -t " + registryHost + "/gentics/mesh-enterprise-mssql:" + version + " --build-arg MESH_VERSION=" + version + " --build-arg MESH_REGISTRY_HOST=" + registryHost + " . ; rm -f mesh-connector.jar ; cd .."
sh "cd .docker ; cp ../ee/connectors/oracle/target/mesh-enterprise-database-connector-oracle-" + mavenVersion + ".jar ./mesh-connector.jar ; docker build --network=host -t " + registryHost + "/gentics/mesh-enterprise-oracle:latest -t " + registryHost + "/gentics/mesh-enterprise-oracle:" + version + " --build-arg MESH_VERSION=" + version + " --build-arg MESH_REGISTRY_HOST=" + registryHost + " . ; rm -f mesh-connector.jar ; cd .."
if (!params.omitScan) {
scanImage image: registryHost + "/gentics/mesh-hsqldb:" + version, exitCode: 1, dockerParams: "-v ${env.WORKSPACE}/build/trivyignore:/tmp/trivyignore", params: "--ignorefile /tmp/trivyignore"
scanImage image: registryHost + "/gentics/mesh-mariadb:" + version, exitCode: 1, dockerParams: "-v ${env.WORKSPACE}/build/trivyignore:/tmp/trivyignore", params: "--ignorefile /tmp/trivyignore"
scanImage image: registryHost + "/gentics/mesh-enterprise-postgres:" + version, exitCode: 1, dockerParams: "-v ${env.WORKSPACE}/build/trivyignore:/tmp/trivyignore", params: "--ignorefile /tmp/trivyignore"
scanImage image: registryHost + "/gentics/mesh-enterprise-mssql:" + version, exitCode: 1, dockerParams: "-v ${env.WORKSPACE}/build/trivyignore:/tmp/trivyignore", params: "--ignorefile /tmp/trivyignore"
scanImage image: registryHost + "/gentics/mesh-enterprise-oracle:" + version, exitCode: 1, dockerParams: "-v ${env.WORKSPACE}/build/trivyignore:/tmp/trivyignore", params: "--ignorefile /tmp/trivyignore"
}
} else {
echo "Docker build skipped.."
}
}
stage("Build Helm Chart") {
if (env.BUILD_SKIPPED != "true" && Boolean.valueOf(params.runHelmBuild)) {
withCredentials([usernamePassword(credentialsId: 'docker.gentics.com', usernameVariable: 'repoUsername', passwordVariable: 'repoPassword')]) {
sh 'REPO_USERNAME=$repoUsername REPO_PASSWORD=$repoPassword .jenkins/build-helm-chart.sh ' + helmVersion
}
} else {
echo "Helm build skipped.."
}
}
stage("Deploy") {
if (env.BUILD_SKIPPED != "true" && (Boolean.valueOf(params.runDeploy) || Boolean.valueOf(params.runDeployTesting))) {
if (Boolean.valueOf(params.runDocker)) {
if (Boolean.valueOf(params.runDeployTesting)) {
registryHost = registryHostTest;
}
withCredentials([usernamePassword(credentialsId: 'docker.gentics.com', usernameVariable: 'repoUsername', passwordVariable: 'repoPassword')]) {
sh 'docker login -u $repoUsername -p $repoPassword ' + registryHost
if (Boolean.valueOf(params.runDeploy)) {
sh 'docker push ' + registryHost + '/gentics/mesh:latest'
sh 'docker push ' + registryHost + '/gentics/mesh-hsqldb:latest'
sh 'docker push ' + registryHost + '/gentics/mesh-mariadb:latest'
sh 'docker push ' + registryHost + '/gentics/mesh/mcp-server:latest'
sh 'docker push ' + registryHost + '/gentics/mesh/content-rag:latest'
sh 'docker push ' + registryHost + '/gentics/mesh-enterprise-postgres:latest'
sh 'docker push ' + registryHost + '/gentics/mesh-enterprise-oracle:latest'
sh 'docker push ' + registryHost + '/gentics/mesh-enterprise-mssql:latest'
}
sh 'docker push ' + registryHost + '/gentics/mesh:' + version
sh 'docker push ' + registryHost + '/gentics/mesh-hsqldb:' + version
sh 'docker push ' + registryHost + '/gentics/mesh-mariadb:' + version
sh 'docker push ' + registryHost + '/gentics/mesh/mcp-server:' + version
sh 'docker push ' + registryHost + '/gentics/mesh/content-rag:' + version
sh 'docker push ' + registryHost + '/gentics/mesh-enterprise-postgres:' + version
sh 'docker push ' + registryHost + '/gentics/mesh-enterprise-oracle:' + version
sh 'docker push ' + registryHost + '/gentics/mesh-enterprise-mssql:' + version
}
}
if (Boolean.valueOf(params.runHelmBuild)) {
if (Boolean.valueOf(params.runDeployTesting)) {
helmRepository = helmRepositoryTest;
}
withCredentials([usernamePassword(credentialsId: 'docker.gentics.com', usernameVariable: 'repoUsername', passwordVariable: 'repoPassword')]) {
def helmPackageFilename = "gentics-mesh-${helmVersion}.tgz"
echo "Deploying Mesh Helm Chart"
sh "curl -u ${repoUsername}:${repoPassword} ${helmRepository} --upload-file target/${helmPackageFilename}"
}
}
// Deployment for JS is a bit tricky, as NPM Registries don't allow one to override/publish
// an already published version again. When you try to do so however, you get an error and everything aborts.
// If 'skipJsLibraries' is true, then we don't have any artifacts to deploy to begin with
// If it's a regular 'runDeploy', then it *should* be safe to deploy, as this is a regular release
// And for test deployments, you need to 'force' deploy it, as we don't know which version one might use,
// which could cause the deployment issue.
if (
!Boolean.valueOf(params.skipJsLibraries)
&& (
Boolean.valueOf(params.runDeploy)
|| (Boolean.valueOf(params.runDeployTesting) && Boolean.valueOf(params.forceJsDeploy))
)
) {
environment {
// Disable colors/special characters, if projects do properly check it
TERM="dumb"
// Disable node based color libraries
FORCE_COLOR="0"
}
// Add private repository credentials and scopes
withCredentials([string(credentialsId: 'nexus-npm', variable: 'NPM_TOKEN')]) {
sh "echo //repo.gentics.com/repository/npm-products/:_auth=${env.NPM_TOKEN} >> ~/.npmrc"
}
dir(path: 'js') {
// Publish the pacakges to artifactory
sh "npm run nx -- release publish"
}
}
} else {
echo "Deploy skipped.."
}
}
stage("Git push") {
if (env.BUILD_SKIPPED != "true" && Boolean.valueOf(params.runDeploy)) {
sshagent(["git"]) {
// First we want to commit + tag the changes pom.xml and package.json files,
// where the verison has changed from x.y.z-SNAPSHOT to just x.y.z for a release.
GitHelper.addCommit('.', gitCommitTag + ' Release of version (' + version + ')')
GitHelper.addTag(version, 'Release of version ' + version)
// Then update all the pom.xml files again to add the -SNAPSHOT suffix again,
// and commit that as a new develop iteration.
def snapshotVersion = MavenHelper.getNextSnapShotVersion(version)
MavenHelper.setVersion(snapshotVersion)
GitHelper.addCommit('.', gitCommitTag + ' Prepare for the next development iteration (' + snapshotVersion + ')')
GitHelper.pushBranch(branchName)
GitHelper.pushTag(version)
}
} else {
echo "Push skipped.."
}
}
} catch (Exception e) {
if (currentBuild.result == null || currentBuild.currentResult == "STABLE") {
currentBuild.result = 'FAILURE'
currentBuild.currentResult = 'FAILURE'
}
throw e
} finally {
deleteDir()
githubBuildEnded()
}
}
}