-
Notifications
You must be signed in to change notification settings - Fork 115
/
Jenkinsfile.split
436 lines (410 loc) · 20.2 KB
/
Jenkinsfile.split
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
// The GIT repository for this pipeline lib is defined in the global Jenkins setting
@Library('jenkins-pipeline-library@nexus')
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: '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: '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."),
string( name: 'testingVersion', defaultValue: "", description: "Version for testing"),
string( name: 'meshVersion', defaultValue: "", description: "Override Mesh version"),
])
])
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-17') {
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")]) {
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-17") {
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)
}
//TODO only add pom.xml files
sh 'git add .'
sh "git commit -m 'Raise version'"
GitHelper.addTag(version, 'Release of version ' + version)
}
}
if (Boolean.valueOf(params.runDeployTesting)) {
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()) {
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")]) {
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("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 {
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)) {
version = branchName;
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 .. "
// 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 .."
} 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)) {
version = branchName;
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
}
}
} else {
echo "Deploy skipped.."
}
}
stage("Git push") {
if (env.BUILD_SKIPPED != "true" && Boolean.valueOf(params.runDeploy)) {
sshagent(["git"]) {
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()
notifyMattermostUsers()
}
}
}