-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathJenkinsfile
439 lines (424 loc) · 24.3 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
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
def isHarnessChange(harnesses) {
def harnessLabels = harnesses.collect { "harness-${it}".toString() } << 'harness-all'
return !env.CHANGE_ID || pullRequest.labels.size() == 0 || harnessLabels.any { pullRequest.labels.contains(it) }
}
def failureMessages = []
pipeline {
agent { label 'linux-amd64' }
environment {
COMPOSE_DOCKER_CLI_BUILD = 1
DOCKER_BUILDKIT = 1
MY127WS_KEY = credentials('base-my127ws-key-20190523')
SLACK_NOTIFICATION_CHANNEL = credentials('slack-notification-channel')
SLACK_TOKEN_CREDENTIAL_ID = credentials('slack-token-credential-id')
}
options {
buildDiscarder(logRotator(daysToKeepStr: '30'))
parallelsAlwaysFailFast()
}
triggers { cron(env.BRANCH_NAME ==~ /^\d+\.\d+\.x$/ ? 'H H(2-6) * * 1' : '') }
stages {
stage('Quality Checks') {
steps {
sh './build'
sh './quality'
milestone(10)
}
post { failure { script { failureMessages << 'Global quality checks' } } }
}
stage('Build and Test') {
parallel {
stage('1. PHP, Drupal, Wordpress') {
// Choose a different agent to our "main" one
agent {
docker {
label 'linux-amd64'
alwaysPull true
image 'quay.io/inviqa_images/workspace:latest'
args '--group-add docker --entrypoint "" --volume /var/run/docker.sock:/var/run/docker.sock --volume "$HOME/.my127:/root/.my127"'
}
}
when {
beforeAgent true
expression { return isHarnessChange(['php', 'drupal', 'wordpress']) }
}
stages {
stage('Prepare') {
steps {
sh './delete_running_containers.sh'
sh './build'
}
post { failure { script { failureMessages << 'PHP, Drupal, Wordpress prepare' } } }
}
stage('Quality Tests') {
environment {
TEARDOWN_ENVIRONMENT = "no"
TEST_MODE = "quality"
}
steps {
sh './test php static'
sh './test drupal10 static'
sh './test drupal9 static'
sh './test drupal8 static'
sh './test wordpress static'
sh './test php dynamic'
sh './test drupal10 dynamic'
sh './test drupal9 dynamic'
sh './test drupal8 dynamic'
sh './test wordpress dynamic'
sh './test php dynamic mutagen'
sh './test drupal10 dynamic mutagen'
sh './test drupal9 dynamic mutagen'
sh './test drupal8 dynamic mutagen'
sh './test wordpress dynamic mutagen'
}
post { failure { script { failureMessages << 'PHP, Drupal, Wordpress quality checks' } } }
}
stage('Acceptance Tests') {
environment {
REUSE_EXISTING_WORKSPACE = "yes"
TEST_MODE = "acceptance"
}
stages {
stage('PHP') {
when { expression { return isHarnessChange(['php']) } }
steps { sh './test php static' }
post { failure { script { failureMessages << 'PHP static acceptance' } } }
}
stage('Drupal 10') {
when { expression { return isHarnessChange(['drupal']) } }
steps { sh './test drupal10 static' }
post { failure { script { failureMessages << 'Drupal 10 static acceptance' } } }
}
stage('Drupal 9') {
when { expression { return isHarnessChange(['drupal']) } }
steps { sh './test drupal9 static' }
post { failure { script { failureMessages << 'Drupal 9 static acceptance' } } }
}
stage('Drupal 8') {
when { expression { return isHarnessChange(['drupal']) } }
steps { sh './test drupal8 static' }
post { failure { script { failureMessages << 'Drupal 8 static acceptance' } } }
}
stage('Wordpress') {
when { expression { return isHarnessChange(['wordpress']) } }
steps { sh './test wordpress static' }
post { failure { script { failureMessages << 'Wordpress static acceptance' } } }
}
stage('PHP Dynamic') {
when { expression { return isHarnessChange(['php']) } }
steps { sh './test php dynamic' }
post { failure { script { failureMessages << 'PHP dynamic acceptance' } } }
}
stage('Drupal 10 Dynamic') {
when { expression { return isHarnessChange(['drupal']) } }
steps { sh './test drupal10 dynamic' }
post { failure { script { failureMessages << 'Drupal 10 dynamic acceptance' } } }
}
stage('Drupal 9 Dynamic') {
when { expression { return isHarnessChange(['drupal']) } }
steps { sh './test drupal9 dynamic' }
post { failure { script { failureMessages << 'Drupal 9 dynamic acceptance' } } }
}
stage('Drupal 8 Dynamic') {
when { expression { return isHarnessChange(['drupal']) } }
steps { sh './test drupal8 dynamic' }
post { failure { script { failureMessages << 'Drupal 8 dynamic acceptance' } } }
}
stage('Wordpress Dynamic') {
when { expression { return isHarnessChange(['wordpress']) } }
steps { sh './test wordpress dynamic' }
post { failure { script { failureMessages << 'Wordpress dynamic acceptance' } } }
}
stage('PHP Mutagen') {
when { expression { return isHarnessChange(['php']) } }
steps { sh './test php dynamic mutagen' }
post { failure { script { failureMessages << 'PHP mutagen acceptance' } } }
}
stage('Drupal 10 Mutagen') {
when { expression { return isHarnessChange(['drupal']) } }
steps { sh './test drupal10 dynamic mutagen' }
post { failure { script { failureMessages << 'Drupal 10 mutagen acceptance' } } }
}
stage('Drupal 9 Mutagen') {
when { expression { return isHarnessChange(['drupal']) } }
steps { sh './test drupal9 dynamic mutagen' }
post { failure { script { failureMessages << 'Drupal 9 mutagen acceptance' } } }
}
stage('Drupal 8 Mutagen') {
when { expression { return isHarnessChange(['drupal']) } }
steps { sh './test drupal8 dynamic mutagen' }
post { failure { script { failureMessages << 'Drupal 8 mutagen acceptance' } } }
}
stage('Wordpress Mutagen') {
when { expression { return isHarnessChange(['wordpress']) } }
steps { sh './test wordpress dynamic mutagen' }
post { failure { script { failureMessages << 'Wordpress mutagen acceptance' } } }
}
}
}
}
// Need to clean up as it's a different agent
post {
always {
sh './delete_running_containers.sh'
cleanWs()
}
}
}
stage('2. Symfony, Magento 2, Magento 1') {
// Choose a different agent to our "main" one
agent {
docker {
label 'linux-amd64'
alwaysPull true
image 'quay.io/inviqa_images/workspace:latest'
args '--group-add docker --entrypoint "" --volume /var/run/docker.sock:/var/run/docker.sock --volume "$HOME/.my127:/root/.my127"'
}
}
when {
beforeAgent true
expression { return isHarnessChange(['symfony', 'magento2', 'magento1']) }
}
stages {
stage('Prepare') {
steps {
sh './delete_running_containers.sh'
sh './build'
}
post { failure { script { failureMessages << 'Symfony, Magento 2, Magento 1 prepare' } } }
}
stage('Quality Tests') {
environment {
TEARDOWN_ENVIRONMENT = "no"
TEST_MODE = "quality"
}
steps {
sh './test symfony static'
sh './test magento2 static'
sh './test magento1 static'
sh './test symfony dynamic'
sh './test magento2 dynamic'
sh './test magento1 dynamic'
sh './test symfony dynamic mutagen'
sh './test magento2 dynamic mutagen'
sh './test magento1 dynamic mutagen'
}
post { failure { script { failureMessages << 'Symfony, Magento 2, Magento 1 quality checks' } } }
}
stage('Acceptance Tests') {
environment {
REUSE_EXISTING_WORKSPACE = "yes"
TEST_MODE = "acceptance"
}
stages {
stage('Symfony') {
when { expression { return isHarnessChange(['symfony']) } }
steps { sh './test symfony static' }
post { failure { script { failureMessages << 'Symfony static acceptance' } } }
}
stage('Magento 2') {
when { expression { return isHarnessChange(['magento2']) } }
options { catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') }
steps { sh './test magento2 static' }
post { failure { script { failureMessages << 'Magento 2 static acceptance' } } }
}
stage('Magento 1') {
when { expression { return isHarnessChange(['magento1']) } }
steps { sh './test magento1 static' }
post { failure { script { failureMessages << 'Magento 1 static acceptance' } } }
}
stage('Symfony Dynamic') {
when { expression { return isHarnessChange(['symfony']) } }
steps { sh './test symfony dynamic' }
post { failure { script { failureMessages << 'Symfony dynamic acceptance' } } }
}
stage('Magento 2 Dynamic') {
when { expression { return isHarnessChange(['magento2']) } }
steps { sh './test magento2 dynamic' }
post { failure { script { failureMessages << 'Magento 2 dynamic acceptance' } } }
}
stage('Magento 1 Dynamic') {
when { expression { return isHarnessChange(['magento1']) } }
steps { sh './test magento1 dynamic' }
post { failure { script { failureMessages << 'Magento 1 dynamic acceptance' } } }
}
stage('Symfony Mutagen') {
when { expression { return isHarnessChange(['symfony']) } }
steps { sh './test symfony dynamic mutagen' }
post { failure { script { failureMessages << 'Symfony mutagen acceptance' } } }
}
stage('Magento 2 Mutagen') {
when { expression { return isHarnessChange(['magento2']) } }
steps { sh './test magento2 dynamic mutagen' }
post { failure { script { failureMessages << 'Magento 2 mutagen acceptance' } } }
}
stage('Magento 1 Mutagen') {
when { expression { return isHarnessChange(['magento1']) } }
steps { sh './test magento1 dynamic mutagen' }
post { failure { script { failureMessages << 'Magento 1 mutagen acceptance' } } }
}
}
}
}
// Need to clean up as it's a different agent
post {
always {
sh './delete_running_containers.sh'
cleanWs()
}
}
}
stage('3. Akeneo') {
agent {
docker {
// Reuse the same agent selected at the top of the file
reuseNode true
label 'linux-amd64'
alwaysPull true
image 'quay.io/inviqa_images/workspace:latest'
args '--group-add docker --entrypoint "" --volume /var/run/docker.sock:/var/run/docker.sock --volume "$HOME/.my127:/root/.my127"'
}
}
when {
beforeAgent true
expression { return isHarnessChange(['akeneo']) }
}
stages {
stage('Prepare') {
steps {
sh './delete_running_containers.sh'
}
post { failure { script { failureMessages << 'Akeneo prepare' } } }
}
stage('Quality Tests') {
environment {
TEARDOWN_ENVIRONMENT = "no"
TEST_MODE = "quality"
}
steps {
sh './test akeneo7 dynamic mutagen'
sh './test akeneo6 dynamic mutagen'
sh './test akeneo5 dynamic mutagen'
sh './test akeneo7 static'
sh './test akeneo6 static'
sh './test akeneo5 static'
sh './test akeneo7 dynamic'
sh './test akeneo6 dynamic'
sh './test akeneo5 dynamic'
}
post { failure { script { failureMessages << 'Akeneo quality checks' } } }
}
stage('Acceptance Tests') {
environment {
REUSE_EXISTING_WORKSPACE = "yes"
TEST_MODE = "acceptance"
}
stages {
stage('Akeneo 7 Mutagen') {
when { expression { return isHarnessChange(['akeneo']) } }
steps { sh './test akeneo7 dynamic mutagen' }
post { failure { script { failureMessages << 'Akeneo 7 mutagen acceptance' } } }
}
stage('Akeneo 6 Mutagen') {
when { expression { return isHarnessChange(['akeneo']) } }
steps { sh './test akeneo6 dynamic mutagen' }
post { failure { script { failureMessages << 'Akeneo 6 mutagen acceptance' } } }
}
stage('Akeneo 5 Mutagen') {
when { expression { return isHarnessChange(['akeneo']) } }
steps { sh './test akeneo5 dynamic mutagen' }
post { failure { script { failureMessages << 'Akeneo 5 mutagen acceptance' } } }
}
stage('Akeneo 7 Static') {
when { expression { return isHarnessChange(['akeneo']) } }
steps { sh './test akeneo7 static' }
post { failure { script { failureMessages << 'Akeneo 7 static acceptance' } } }
}
stage('Akeneo 6 Static') {
when { expression { return isHarnessChange(['akeneo']) } }
steps { sh './test akeneo6 static' }
post { failure { script { failureMessages << 'Akeneo 6 static acceptance' } } }
}
stage('Akeneo 5 Static') {
when { expression { return isHarnessChange(['akeneo']) } }
steps { sh './test akeneo5 static' }
post { failure { script { failureMessages << 'Akeneo 5 static acceptance' } } }
}
stage('Akeneo 7 Dynamic') {
when { expression { return isHarnessChange(['akeneo']) } }
steps { sh './test akeneo7 dynamic' }
post { failure { script { failureMessages << 'Akeneo 7 dynamic acceptance' } } }
}
stage('Akeneo 6 Dynamic') {
when { expression { return isHarnessChange(['akeneo']) } }
steps { sh './test akeneo6 dynamic' }
post { failure { script { failureMessages << 'Akeneo 6 dynamic acceptance' } } }
}
stage('Akeneo 5 Dynamic') {
when { expression { return isHarnessChange(['akeneo']) } }
steps { sh './test akeneo5 dynamic' }
post { failure { script { failureMessages << 'Akeneo 5 dynamic acceptance' } } }
}
}
}
}
// No post step, as it will be taken care of in the global cleanup at the bottom
}
}
}
stage('Success') {
steps {
sh 'echo "Success"'
milestone(100)
}
}
}
post {
failure {
script {
def message = "${env.JOB_NAME} #${env.BUILD_NUMBER} - Failure after ${currentBuild.durationString.minus(' and counting')} (<${env.RUN_DISPLAY_URL}|View Build>)"
def fallbackMessages = [ message ]
def fields = []
def shortCommitHash = "${GIT_COMMIT}".substring(0, 7)
def commitLink = "<https://github.com/inviqa/harness-base-php/commit/${GIT_COMMIT}|${shortCommitHash}>"
def gitMessage = "Branch <https://github.com/inviqa/harness-base-php/tree/${GIT_BRANCH}|${GIT_BRANCH}> @ ${commitLink}"
if (env.CHANGE_URL) {
// Jenkins builds pull requests by merging the pull request branch into the pull request's target branch,
// so we build on commits that do not technically exist and can't link to them.
gitMessage = "<${env.CHANGE_URL}|Pull Request #${env.CHANGE_ID}> ${env.CHANGE_TITLE} - merged into target branch <https://github.com/inviqa/harness-base-php/tree/${CHANGE_TARGET}|${CHANGE_TARGET}>"
}
fields << [
title: 'Source',
value: gitMessage,
short: false
]
fallbackMessages << gitMessage
def failureMessage = failureMessages.join("\n")
if (failureMessage) {
fields << [
title: 'Reason(s)',
value: failureMessage,
short: false
]
fallbackMessages << failureMessage
}
def attachments = [
[
text: message,
fallback: fallbackMessages.join("\n"),
color: 'danger',
fields: fields
]
]
if (!env.CHANGE_ID || !pullRequest.draft) {
slackSend (channel: env.SLACK_NOTIFICATION_CHANNEL, color: 'danger', attachments: attachments, tokenCredentialId: env.SLACK_TOKEN_CREDENTIAL_ID)
}
}
}
always {
sh './delete_running_containers.sh'
cleanWs()
}
}
}