forked from gentics/mesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.split
282 lines (263 loc) · 10.6 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
// 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: 'runTests', defaultValue: true, description: "Whether to run the unit tests"),
booleanParam(name: 'splitTests', defaultValue: true, description: "Whether to split tests or not"),
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: '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: '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.")
])
])
final def gitCommitTag = '[Jenkins | ' + env.JOB_BASE_NAME + ']';
final def splits = 20;
final def runs = 20;
final def imagePrefix = "gtx-docker-releases-staging-mesh.docker.apa-it.at/";
stage("Setup Build Environment") {
node("mesh-root-worker-11") {
githubBuildStarted()
try {
stage("Checkout") {
checkout scm
}
def branchName = GitHelper.fetchCurrentBranchName()
def version = MavenHelper.getVersion()
stage("Set Version") {
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)
}
}
stage("Prebuild") {
if (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: 'gentics.gpg', usernameVariable: 'gpgKeyName', passwordVariable: 'gpgKeyPass')]) {
sh "mvn -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 (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
branches["split${current}"] = {
node('mesh-worker-11') {
echo "Preparing slave environment for ${current}"
sh "rm -rf split${current}"
sh "mkdir split${current}"
dir("split${current}") {
unstash 'project'
def postfix = current;
if (current <= 9) {
postfix = "0" + current
}
sshagent(["git"]) {
try {
def jacoco = Boolean.valueOf(params.runSonar);
sh ".jenkins/run-splits.sh includes-${postfix} ${jacoco}"
stash name: "jacoco" + current, includes: "**/jacoco-partial.exec", allowEmpty: true
} finally {
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/*.xml'])
deleteDir()
}
}
}
}
}
}
try {
parallel branches
} catch (err) {
echo "Failed " + err.getMessage()
error err.getMessage()
}
} else {
sshagent(["git"]) {
try {
sh "mvn -fae -Dsurefire.excludedGroups=com.gentics.mesh.test.category.FailingTests -Dmaven.javadoc.skip=true -Dskip.cluster.tests=true -Dmaven.test.failure.ignore=true -B -U -e -pl '!ferma,!demo,!doc,!performance-tests' clean install"
} finally {
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/*.xml'])
}
}
}
} else {
echo "Tests skipped.."
}
}
stage("Unstable Tests") {
if (Boolean.valueOf(params.runUnstableTests)) {
sshagent(["git"]) {
try {
sh "mvn -fae -Dsurefire.groups=com.gentics.mesh.test.category.FailingTests -Dmaven.javadoc.skip=true -Dskip.cluster.tests=true -Dmaven.test.failure.ignore=true -B -e -pl '!ferma,!demo,!doc,!performance-tests' test -DfailIfNoTests=false"
} finally {
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/*.xml'])
}
}
} else {
echo "Failing test group execution skipped.."
}
}
stage("Maven Build") {
if (Boolean.valueOf(params.runMavenBuild)) {
sshagent(["git"]) {
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: 'repo.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 {
sh "mvn -B -DskipTests clean package"
}
}
} else {
echo "Maven build skipped.."
}
}
stage ("Sonar") {
if (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 (Boolean.valueOf(params.runClusterTests)) {
stash includes: '**', name: 'project'
node("mesh-cluster-worker-11") {
try {
unstash 'project'
sh "mvn -B -DskipTests clean install -pl '!demo,!doc'"
sh "mvn -B test -pl distributed"
} finally {
step([$class: 'JUnitResultArchiver', testResults: 'distributed/target/surefire-reports/*.xml'])
deleteDir()
}
}
} else {
echo "Cluster tests skipped.."
}
}
stage("Docker Build") {
if (Boolean.valueOf(params.runDocker)) {
// demo
sh "rm demo/target/*sources.jar || true"
sh "rm demo/target/*javadoc.jar || true"
sh "cd demo ; docker build --network=host -t " + imagePrefix + "gentics/mesh-demo:latest -t " + imagePrefix + "gentics/mesh-demo:" + version + " . "
// server
sh "rm server/target/*sources.jar || true"
sh "rm server/target/*javadoc.jar || true"
sh "cd server ; docker build --network=host -t " + imagePrefix + "gentics/mesh:latest -t " + imagePrefix + "gentics/mesh:" + version + " . "
} else {
echo "Docker build skipped.."
}
}
stage("Performance Tests") {
if (Boolean.valueOf(params.runPerformanceTests)) {
stash includes: '**', name: 'project'
node("mesh-performance-worker-11") {
try {
unstash 'project'
sh "mvn -B -U clean package -pl '!doc,!demo,!server' -Dskip.unit.tests=true -Dskip.cluster.tests=true -Dskip.performance.tests=false -Dmaven.test.failure.ignore=true"
} finally {
step([$class: 'JUnitResultArchiver', testResults: '**/target/*.performance.xml'])
deleteDir()
}
}
} else {
echo "Performance tests skipped.."
}
}
stage("Integration Tests") {
if (Boolean.valueOf(params.runIntegrationTests)) {
withEnv(["MESH_VERSION=" + version]) {
sh "integration-tests/test.sh"
}
} else {
echo "Performance tests skipped.."
}
}
stage("Deploy") {
if (Boolean.valueOf(params.runDeploy)) {
if (Boolean.valueOf(params.runDocker)) {
withCredentials([usernamePassword(credentialsId: 'repo.gentics.com', usernameVariable: 'repoUsername', passwordVariable: 'repoPassword')]) {
sh 'docker login -u $repoUsername -p $repoPassword gtx-docker-releases-staging-mesh.docker.apa-it.at'
sh 'docker push ' + imagePrefix + 'gentics/mesh-demo:latest'
sh 'docker push ' + imagePrefix + 'gentics/mesh-demo:' + version
sh 'docker push ' + imagePrefix + 'gentics/mesh:latest'
sh 'docker push ' + imagePrefix + 'gentics/mesh:' + version
}
}
} else {
echo "Deploy skipped.."
}
}
stage("Git push") {
if (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()
}
}
}