Repository navigation
Expand file tree
/
Copy pathJenkinsfile.split
More file actions
557 lines (516 loc) · 26.1 KB
/
Copy pathJenkinsfile.split
File metadata and controls
557 lines (516 loc) · 26.1 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
// 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: 'splitTests', defaultValue: true, description: "Whether to split tests across chunks and databases"),
booleanParam(name: 'testHsqlm', defaultValue: true , description: "Whether to test HSQLDB In-Memory context"),
booleanParam(name: 'testMaria', defaultValue: false, description: "Whether to test MariaDB context"),
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: true, description: "Whether to run tests in failing group."),
booleanParam(name: 'runPerformanceTests', defaultValue: false, description: "Whether to run performance tests."),
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: '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: '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."),
booleanParam(name: 'runDocker', defaultValue: false, description: "Whether to run the docker steps."),
booleanParam(name: 'omitScan', defaultValue: false, description: "Omit scanning the docker images"),
booleanParam(name: 'runMavenBuild', defaultValue: false, description: "Whether to run the maven 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: 'runIntegrationTests', defaultValue: false, description: "Whether to run integration tests."),
booleanParam(name: 'consistencyChecks', defaultValue: false, description: "Whether to do consistency checks for every test. Enabling this will increase overall test runtime."),
booleanParam(name: 'skipJsLibraries', defaultValue: false, description: "Whether to skip deployment of Javascript/Typescript libraries"),
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"),
])
])
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";
def registryHost = registryHostStaging;
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 noHsqldb = true
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 (Boolean.valueOf(params.testMaria)) {
sh "mvn -pl :mesh-database-connector-mariadb docker:start -Dskip.mariadb.tests=${noMariadb} "
}
// run the 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}"
}
} finally {
// finally stop the docker containers
if (Boolean.valueOf(params.testMaria)) {
sh "mvn -pl :mesh-database-connector-mariadb docker:stop -Dskip.mariadb.tests=${noMariadb} "
}
}
}
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()
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)
}
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 -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") {
if (env.BUILD_SKIPPED != "true" && Boolean.valueOf(params.runTests)) {
if (Boolean.valueOf(params.splitTests)) {
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)) {
testPart("mariadb", current, branches)
} else {
echo "MariaDB split skipped.."
}
if (Boolean.valueOf(params.testHsqlm)) {
testPart("hsqlm", current, branches)
} else {
echo "MariaDB split skipped.."
}
}
try {
parallel branches
} catch (err) {
echo "Failed " + err.getMessage()
error err.getMessage()
}
} else {
sshagent(["git"]) {
def noMariadb = true
def noHsqldb = true
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.mariadb.tests=${noMariadb} -Dskip.hsqlmemory.tests=${noHsqldb} -B -U -e test"
}
}
} finally {
step([$class: 'JUnitResultArchiver', testResults: '**/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' 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"]) {
def noMariadb = true
if (Boolean.valueOf(params.testMaria)) {
noMariadb = false
} else {
echo "MariaDB skipped.."
}
withCredentials([
usernamePassword(credentialsId: 'docker.gentics.com', usernameVariable: 'repoUsername', passwordVariable: 'repoPassword'),
usernamePassword(credentialsId: 'gentics.gpg', usernameVariable: 'gpgKeyName', passwordVariable: 'gpgKeyPass')
]) {
try {
// first we start the test db manager
sh 'docker login -u $repoUsername -p $repoPassword docker.gentics.com'
sh "mvn -pl :mesh-database-connector-mariadb docker:start -Dskip.mariadb.tests=${noMariadb} "
if (!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
sh "mvn -pl :mesh-database-connector-mariadb docker:stop -Dskip.mariadb.tests=${noMariadb} "
}
}
}
} 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,:mesh-database-connector-mariadb,:mesh-database-connector-hsqldb,bom,plugin-bom,plugin-parent' 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 ("Sonar") {
if (env.BUILD_SKIPPED != "true" && Boolean.valueOf(params.runTests) && Boolean.valueOf(params.runSonar)) {
if (Boolean.valueOf(params.splitTests)) {
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"
//sh "mvn sonar:sonar -Dsonar.projectKey=mesh -Dsonar.host.url=https://sonarqube.apa.at -Dsonar.login=$TOKEN"
}
}
}
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 .. "
if (!params.omitScan) {
scanImage image: registryHost + "/gentics/mesh:" + 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 .."
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"
}
} else {
echo "Docker build skipped.."
}
}
stage("Performance Tests") {
if (env.BUILD_SKIPPED != "true" && Boolean.valueOf(params.runPerformanceTests)) {
stash includes: '**', name: 'project'
node("mesh-performance-worker-17") {
try {
unstash 'project'
sh "mvn -B -U clean package -pl '!doc,!server' -Dskip.unit.tests=true -Dskip.cluster.tests=true -Dskip.performance.tests=false -Dmaven.test.failure.ignore=true -Dmesh.container.image.prefix=docker.gentics.com/"
} finally {
step([$class: 'JUnitResultArchiver', testResults: '**/target/*.performance.xml'])
deleteDir()
}
}
} else {
echo "Performance tests skipped.."
}
}
stage("Integration Tests") {
if (env.BUILD_SKIPPED != "true" && Boolean.valueOf(params.runIntegrationTests)) {
withEnv(["MESH_VERSION=" + version]) {
sh "integration-tests/test.sh"
}
} else {
echo "Performance tests 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:' + version
sh 'docker push ' + registryHost + '/gentics/mesh-hsqldb:' + version
sh 'docker push ' + registryHost + '/gentics/mesh-mariadb:' + version
}
}
// 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()
}
}
}