forked from camunda/camunda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
343 lines (299 loc) · 13.1 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
// vim: set filetype=groovy:
@Library(["camunda-ci", "zeebe-jenkins-shared-library"]) _
def buildName = "${env.JOB_BASE_NAME.replaceAll("%2F", "-").replaceAll("\\.", "-").take(20)}-${env.BUILD_ID}"
def masterBranchName = 'master'
def isMasterBranch = env.BRANCH_NAME == masterBranchName
def developBranchName = 'develop'
def isDevelopBranch = env.BRANCH_NAME == developBranchName
//for develop branch keep builds for 7 days to be able to analyse build errors, for all other branches, keep the last 10 builds
def daysToKeep = isDevelopBranch ? '7' : '-1'
def numToKeep = isDevelopBranch ? '-1' : '10'
//the develop branch should be run hourly to detect flaky tests and instability, other branches only on commit
def cronTrigger = isDevelopBranch ? '@hourly' : ''
pipeline {
agent {
kubernetes {
cloud 'zeebe-ci'
label "zeebe-ci-build_${buildName}"
defaultContainer 'jnlp'
yamlFile '.ci/podSpecs/distribution.yml'
}
}
environment {
NEXUS = credentials("camunda-nexus")
SONARCLOUD_TOKEN = credentials('zeebe-sonarcloud-token')
}
triggers {
cron(cronTrigger)
}
options {
buildDiscarder(logRotator(daysToKeepStr: daysToKeep, numToKeepStr: numToKeep))
timestamps()
timeout(time: 45, unit: 'MINUTES')
}
stages {
stage('Prepare') {
steps {
script {
commit_summary = sh([returnStdout: true, script: 'git show -s --format=%s']).trim()
displayNameFull = "#" + BUILD_NUMBER + ': ' + commit_summary
if (displayNameFull.length() <= 45) {
currentBuild.displayName = displayNameFull
} else {
displayStringHardTruncate = displayNameFull.take(45)
currentBuild.displayName = displayStringHardTruncate.take(displayStringHardTruncate.lastIndexOf(" "))
}
}
container('maven') {
sh '.ci/scripts/distribution/prepare.sh'
}
container('maven-jdk8') {
sh '.ci/scripts/distribution/prepare.sh'
}
container('golang') {
sh '.ci/scripts/distribution/prepare-go.sh'
}
}
}
stage('Build (Java)') {
steps {
container('maven') {
configFileProvider([configFile(fileId: 'maven-nexus-settings-zeebe', variable: 'MAVEN_SETTINGS_XML')]) {
sh '.ci/scripts/distribution/build-java.sh'
}
}
}
}
stage('Prepare Tests') {
environment {
IMAGE = "camunda/zeebe"
VERSION = readMavenPom(file: 'parent/pom.xml').getVersion()
TAG = 'current-test'
}
steps {
container('maven') {
sh 'cp dist/target/zeebe-distribution-*.tar.gz zeebe-distribution.tar.gz'
}
container('docker') {
sh '.ci/scripts/docker/build.sh'
sh '.ci/scripts/docker/build_zeebe-hazelcast-exporter.sh'
}
}
}
stage('Test') {
parallel {
stage('Go') {
steps {
container('golang') {
sh '.ci/scripts/distribution/build-go.sh'
}
container('golang') {
sh '.ci/scripts/distribution/test-go.sh'
}
}
post {
always {
junit testResults: "**/*/TEST-go.xml", keepLongStdio: true
}
}
}
stage('Analyse (Java)') {
steps {
container('maven') {
configFileProvider([configFile(fileId: 'maven-nexus-settings-zeebe', variable: 'MAVEN_SETTINGS_XML')]) {
sh '.ci/scripts/distribution/analyse-java.sh'
}
}
}
}
stage('Unit (Java)') {
environment {
SUREFIRE_REPORT_NAME_SUFFIX = 'java-testrun'
}
steps {
container('maven') {
configFileProvider([configFile(fileId: 'maven-nexus-settings-zeebe', variable: 'MAVEN_SETTINGS_XML')]) {
sh '.ci/scripts/distribution/test-java.sh'
}
}
}
post {
always {
junit testResults: "**/*/TEST*${SUREFIRE_REPORT_NAME_SUFFIX}*.xml", keepLongStdio: true
}
}
}
stage('Unit 8 (Java 8)') {
environment {
SUREFIRE_REPORT_NAME_SUFFIX = 'java8-testrun'
}
steps {
container('maven-jdk8') {
configFileProvider([configFile(fileId: 'maven-nexus-settings-zeebe', variable: 'MAVEN_SETTINGS_XML')]) {
sh '.ci/scripts/distribution/test-java8.sh'
}
}
}
post {
always {
junit testResults: "**/*/TEST*${SUREFIRE_REPORT_NAME_SUFFIX}*.xml", keepLongStdio: true
}
}
}
stage('IT (Java)') {
agent {
kubernetes {
cloud 'zeebe-ci'
label "zeebe-ci-build_${buildName}_it"
defaultContainer 'jnlp'
yamlFile '.ci/podSpecs/distribution.yml'
}
}
environment {
SUREFIRE_REPORT_NAME_SUFFIX = 'it-testrun'
NEXUS = credentials("camunda-nexus")
IMAGE = "camunda/zeebe"
VERSION = readMavenPom(file: 'parent/pom.xml').getVersion()
TAG = 'current-test'
}
steps {
container('maven') {
configFileProvider([configFile(fileId: 'maven-nexus-settings-zeebe', variable: 'MAVEN_SETTINGS_XML')]) {
sh '.ci/scripts/distribution/prepare.sh'
sh '.ci/scripts/distribution/build-java.sh'
sh 'cp dist/target/zeebe-distribution-*.tar.gz zeebe-distribution.tar.gz'
}
}
container('docker') {
sh '.ci/scripts/docker/build.sh'
}
container('maven') {
configFileProvider([configFile(fileId: 'maven-nexus-settings-zeebe', variable: 'MAVEN_SETTINGS_XML')]) {
sh '.ci/scripts/distribution/it-java.sh'
}
}
}
post {
always {
junit testResults: "**/*/TEST*${SUREFIRE_REPORT_NAME_SUFFIX}*.xml", keepLongStdio: true
}
}
}
stage('BPMN TCK') {
steps {
container('maven') {
configFileProvider([configFile(fileId: 'maven-nexus-settings-zeebe', variable: 'MAVEN_SETTINGS_XML')]) {
sh '.ci/scripts/distribution/test-tck.sh'
}
}
}
post {
always {
junit testResults: "bpmn-tck/**/*/TEST*.xml", keepLongStdio: true
}
}
}
}
post {
always {
jacoco(
execPattern: '**/*.exec',
classPattern: '**/target/classes',
sourcePattern: '**/src/main/java,**/generated-sources/protobuf/java,**/generated-sources/assertj-assertions,**/generated-sources/sbe',
exclusionPattern: '**/io/zeebe/gateway/protocol/**,'
+ '**/*Encoder.class,**/*Decoder.class,**/MetaAttribute.class,'
+ '**/io/zeebe/protocol/record/**/*Assert.class,**/io/zeebe/protocol/record/Assertions.class,', // classes from generated resources
runAlways: true
)
zip zipFile: 'test-coverage-reports.zip', archive: true, glob: "**/target/site/jacoco/**"
}
failure {
zip zipFile: 'test-reports.zip', archive: true, glob: "**/*/surefire-reports/**"
archive "**/hs_err_*.log"
script {
if (fileExists('./target/FlakyTests.txt')) {
currentBuild.description = "Flaky Tests: <br>" + readFile('./target/FlakyTests.txt').split('\n').join('<br>')
}
}
}
}
}
stage('Upload') {
when { allOf { branch developBranchName; not { triggeredBy 'TimerTrigger' } } }
steps {
retry(3) {
container('maven') {
configFileProvider([configFile(fileId: 'maven-nexus-settings-zeebe', variable: 'MAVEN_SETTINGS_XML')]) {
sh '.ci/scripts/distribution/upload.sh'
}
}
}
}
}
stage('Post') {
when { not { triggeredBy 'TimerTrigger' } }
parallel {
stage('Docker') {
when { branch developBranchName }
environment {
VERSION = readMavenPom(file: 'parent/pom.xml').getVersion()
}
steps {
retry(3) {
build job: 'zeebe-docker', parameters: [
string(name: 'BRANCH', value: env.BRANCH_NAME),
string(name: 'VERSION', value: env.VERSION),
booleanParam(name: 'IS_LATEST', value: isMasterBranch),
booleanParam(name: 'PUSH', value: isDevelopBranch)
]
}
}
}
}
}
}
post {
always {
// Retrigger the build if there were connection issues
script {
if (agentDisconnected()) {
currentBuild.result = 'ABORTED'
currentBuild.description = "Aborted due to connection error"
build job: currentBuild.projectName, propagate: false, quietPeriod: 60, wait: false
}
String userReason = null
if (currentBuild.description ==~ /.*Flaky Tests.*/) {
userReason = 'flaky-tests'
}
org.camunda.helper.CIAnalytics.trackBuildStatus(this, userReason)
}
}
failure {
script {
if (env.BRANCH_NAME != 'develop' || agentDisconnected()) {
return
}
echo "Send slack message"
slackSend(
channel: "#zeebe-ci${jenkins.model.JenkinsLocationConfiguration.get()?.getUrl()?.contains('stage') ? '-stage' : ''}",
message: "Zeebe ${env.BRANCH_NAME} build ${currentBuild.absoluteUrl} changed status to ${currentBuild.currentResult}")
}
}
changed {
script {
if (env.BRANCH_NAME != 'develop' || agentDisconnected()) {
return
}
if (currentBuild.currentResult == 'FAILURE') {
return // already handled above
}
if (hasBuildResultChanged()) {
echo "Send slack message"
slackSend(
channel: "#zeebe-ci${jenkins.model.JenkinsLocationConfiguration.get()?.getUrl()?.contains('stage') ? '-stage' : ''}",
message: "Zeebe ${env.BRANCH_NAME} build ${currentBuild.absoluteUrl} changed status to ${currentBuild.currentResult}")
}
}
}
}
}