forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
715 lines (705 loc) · 21.7 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
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
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
#!/usr/bin/env groovy
@Library('apm@current') _
pipeline {
agent { label 'ubuntu && immutable' }
environment {
BASE_DIR = 'src/github.com/elastic/beats'
GOX_FLAGS = "-arch amd64"
DOCKER_COMPOSE_VERSION = "1.21.0"
}
options {
timeout(time: 2, unit: 'HOURS')
buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20', daysToKeepStr: '30'))
timestamps()
ansiColor('xterm')
disableResume()
durabilityHint('PERFORMANCE_OPTIMIZED')
disableConcurrentBuilds()
// checkoutToSubdirectory "${env.BASE_DIR}"
}
triggers {
issueCommentTrigger('(?i).*(?:jenkins\\W+)?run\\W+(?:the\\W+)?tests(?:\\W+please)?.*')
}
parameters {
booleanParam(name: 'runAllStages', defaultValue: false, description: 'Allow to run all stages.')
booleanParam(name: 'windowsTest', defaultValue: true, description: 'Allow Windows stages.')
}
stages {
/**
Checkout the code and stash it, to use it on other stages.
*/
stage('Checkout') {
options { skipDefaultCheckout() }
steps {
deleteDir()
gitCheckout(basedir: "${BASE_DIR}")
dir("${BASE_DIR}"){
loadConfigEnvVars()
}
stash allowEmpty: true, name: 'source', useDefaultExcludes: false
}
}
stage('Lint'){
options { skipDefaultCheckout() }
steps {
makeTarget("Lint", "check")
}
}
stage('Build and Test'){
failFast false
parallel {
stage('Filebeat oss'){
agent { label 'ubuntu && immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return env.BUILD_FILEBEAT != "false"
}
}
steps {
makeTarget("Filebeat oss Linux", "-C filebeat testsuite")
}
}
stage('Filebeat x-pack'){
agent { label 'ubuntu && immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return env.BUILD_FILEBEAT_XPACK != "false"
}
}
steps {
makeTarget("Filebeat x-pack Linux", "-C x-pack/filebeat testsuite")
}
}
stage('Filebeat Mac OS X'){
agent { label 'macosx' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return env.BUILD_FILEBEAT != "false"
}
}
steps {
makeTarget("Filebeat oss Mac OS X", "TEST_ENVIRONMENT=0 -C filebeat testsuite")
}
}
stage('Filebeat Windows'){
agent { label 'windows-immutable && windows-2019' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return env.BUILD_FILEBEAT != "false" && params.windowsTest
}
}
steps {
mageTargetWin("Filebeat oss Windows Unit test", "-d filebeat goUnitTest")
//mageTargetWin("Filebeat oss Windows Integration test", "-d filebeat goIntegTest")
}
}
stage('Heartbeat'){
agent { label 'ubuntu && immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return env.BUILD_HEARTBEAT != "false"
}
}
stages {
stage('Heartbeat oss'){
steps {
makeTarget("Heartbeat oss Linux", "-C heartbeat testsuite")
}
}
stage('Heartbeat Mac OS X'){
agent { label 'macosx' }
options { skipDefaultCheckout() }
steps {
makeTarget("Heartbeat oss Mac OS X", "TEST_ENVIRONMENT=0 -C heartbeat testsuite")
}
}
stage('Heartbeat Windows'){
agent { label 'windows-immutable && windows-2019' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return params.windowsTest
}
}
steps {
mageTargetWin("Heartbeat oss Windows Unit test", "-d heartbeat goTestUnit")
}
}
}
}
stage('Auditbeat oss'){
agent { label 'ubuntu && immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return env.BUILD_AUDITBEAT != "false"
}
}
stages {
stage('Auditbeat Linux'){
steps {
makeTarget("Auditbeat oss Linux", "-C auditbeat testsuite")
}
}
stage('Auditbeat crosscompile'){
steps {
makeTarget("Auditbeat oss crosscompile", "-C auditbeat crosscompile")
}
}
stage('Auditbeat Mac OS X'){
agent { label 'macosx' }
options { skipDefaultCheckout() }
steps {
makeTarget("Auditbeat oss Mac OS X", "TEST_ENVIRONMENT=0 -C auditbeat testsuite")
}
}
stage('Auditbeat Windows'){
agent { label 'windows-immutable && windows-2019' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return params.windowsTest
}
}
steps {
mageTargetWin("Auditbeat Windows Unit test", "-d auditbeat goUnitTest")
//mageTargetWin("Auditbeat Windows Integration test", "-d auditbeat goIntegTest")
}
}
}
}
stage('Auditbeat x-pack'){
agent { label 'ubuntu && immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return env.BUILD_AUDITBEAT_XPACK != "false"
}
}
steps {
makeTarget("Auditbeat x-pack Linux", "-C x-pack/auditbeat testsuite")
}
}
stage('Libbeat'){
agent { label 'ubuntu && immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return env.BUILD_LIBBEAT != "false"
}
}
stages {
stage('Libbeat oss'){
steps {
makeTarget("Libbeat oss Linux", "-C libbeat testsuite")
}
}
stage('Libbeat crosscompile'){
steps {
makeTarget("Libbeat oss crosscompile", "-C libbeat crosscompile")
}
}
stage('Libbeat stress-tests'){
steps {
makeTarget("Libbeat stress-tests", "STRESS_TEST_OPTIONS='-timeout=20m -race -v -parallel 1' -C libbeat stress-tests")
}
}
}
}
stage('Libbeat x-pack'){
agent { label 'ubuntu && immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return env.BUILD_LIBBEAT_XPACK != "false"
}
}
steps {
makeTarget("Libbeat x-pack Linux", "-C x-pack/libbeat testsuite")
}
}
stage('Metricbeat Unit tests'){
agent { label 'ubuntu && immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return env.BUILD_METRICBEAT != "false"
}
}
steps {
makeTarget("Metricbeat Unit tests", "-C metricbeat unit-tests coverage-report")
}
}
stage('Metricbeat Integration tests'){
agent { label 'ubuntu && immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return env.BUILD_METRICBEAT != "false"
}
}
steps {
makeTarget("Metricbeat Integration tests", "-C metricbeat integration-tests-environment coverage-report")
}
}
stage('Metricbeat System tests'){
agent { label 'ubuntu && immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return env.BUILD_METRICBEAT != "false"
}
}
steps {
makeTarget("Metricbeat System tests", "-C metricbeat update system-tests-environment coverage-report")
}
}
stage('Metricbeat x-pack'){
agent { label 'ubuntu && immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return env.BUILD_METRICBEAT_XPACK != "false"
}
}
steps {
makeTarget("Metricbeat x-pack Linux", "-C x-pack/metricbeat testsuite")
}
}
stage('Metricbeat crosscompile'){
agent { label 'ubuntu && immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return env.BUILD_METRICBEAT != "false"
}
}
steps {
makeTarget("Metricbeat oss crosscompile", "-C metricbeat crosscompile")
}
}
stage('Metricbeat Mac OS X'){
agent { label 'macosx' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return env.BUILD_METRICBEAT != "false"
}
}
steps {
makeTarget("Metricbeat oss Mac OS X", "TEST_ENVIRONMENT=0 -C metricbeat testsuite")
}
}
stage('Metricbeat Windows'){
agent { label 'windows-immutable && windows-2019' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return env.BUILD_METRICBEAT != "false" && params.windowsTest
}
}
steps {
mageTargetWin("Metricbeat Windows Unit test", "-d metricbeat goUnitTest")
//mageTargetWin("Metricbeat Windows Integration test", "-d metricbeat goIntegTest")
}
}
stage('Packetbeat'){
agent { label 'ubuntu && immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return env.BUILD_PACKETBEAT != "false"
}
}
stages {
stage('Packetbeat oss'){
steps {
makeTarget("Packetbeat oss Linux", "-C packetbeat testsuite")
}
}
}
}
stage('dockerlogbeat'){
agent { label 'ubuntu && immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return env.BUILD_DOCKERLOGBEAT_XPACK != "false"
}
}
stages {
stage('Dockerlogbeat'){
steps {
makeTarget("Elastic Log Plugin unit tests", "-C x-pack/dockerlogbeat testsuite")
}
}
}
}
stage('Winlogbeat'){
agent { label 'ubuntu && immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return env.BUILD_WINLOGBEAT != "false"
}
}
stages {
stage('Winlogbeat oss'){
steps {
makeTarget("Winlogbeat oss crosscompile", "-C winlogbeat crosscompile")
}
}
stage('Winlogbeat Windows'){
agent { label 'windows-immutable && windows-2019' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return params.windowsTest
}
}
steps {
mageTargetWin("Winlogbeat Windows Unit test", "-d winlogbeat goUnitTest")
}
}
}
}
stage('Winlogbeat Windows x-pack'){
agent { label 'windows-immutable && windows-2019' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return params.windowsTest && env.BUILD_WINLOGBEAT_XPACK != "false"
}
}
steps {
mageTargetWin("Winlogbeat Windows Unit test", "-d x-pack/winlogbeat update:fields goUnitTest")
}
}
stage('Functionbeat'){
agent { label 'ubuntu && immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return env.BUILD_FUNCTIONBEAT_XPACK != "false"
}
}
stages {
stage('Functionbeat x-pack'){
steps {
makeTarget("Functionbeat x-pack Linux", "-C x-pack/functionbeat testsuite")
}
}
stage('Functionbeat Mac OS X x-pack'){
agent { label 'macosx' }
options { skipDefaultCheckout() }
steps {
makeTarget("Functionbeat x-pack Mac OS X", "TEST_ENVIRONMENT=0 -C x-pack/functionbeat testsuite")
}
}
stage('Functionbeat Windows'){
agent { label 'windows-immutable && windows-2019' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return params.windowsTest
}
}
steps {
mageTargetWin("Functionbeat Windows Unit test", "-d x-pack/functionbeat goUnitTest")
}
}
}
}
stage('Journalbeat'){
agent { label 'ubuntu && immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return env.BUILD_JOURNALBEAT != "false"
}
}
stages {
stage('Journalbeat oss'){
steps {
makeTarget("Journalbeat Linux", "-C journalbeat testsuite")
}
}
}
}
stage('Generators'){
agent { label 'ubuntu && immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return env.BUILD_GENERATOR != "false"
}
}
stages {
stage('Generators Metricbeat Linux'){
steps {
makeTarget("Generators Metricbeat Linux", "-C generator/metricbeat test")
makeTarget("Generators Metricbeat Linux", "-C generator/metricbeat test-package")
}
}
stage('Generators Beat Linux'){
steps {
makeTarget("Generators Beat Linux", "-C generator/beat test")
makeTarget("Generators Beat Linux", "-C generator/beat test-package")
}
}
stage('Generators Metricbeat Mac OS X'){
agent { label 'macosx' }
options { skipDefaultCheckout() }
steps {
makeTarget("Generators Metricbeat Mac OS X", "-C generator/metricbeat test")
}
}
stage('Generators Beat Mac OS X'){
agent { label 'macosx' }
options { skipDefaultCheckout() }
steps {
makeTarget("Generators Beat Mac OS X", "-C generator/beat test")
}
}
}
}
stage('Kubernetes'){
agent { label 'ubuntu && immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression {
return env.BUILD_KUBERNETES != "false"
}
}
steps {
k8sTest(["v1.16.2","v1.15.3","v1.14.6","v1.13.10","v1.12.10","v1.11.10"])
}
}
stage('Docs'){
agent { label 'ubuntu && immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression { return env.BUILD_DOCS != "false" }
}
steps {
makeTarget("Docs", "docs")
}
}
}
}
}
}
def makeTarget(context, target, clean = true){
withGithubNotify(context: "${context}") {
withBeatsEnv(){
sh(label: "Make ${target}", script: """
eval "\$(gvm use ${GO_VERSION} --format=bash)"
make ${target}
""")
if(clean) {
sh(script: 'script/fix_permissions.sh ${HOME}')
}
}
}
}
def mageTargetWin(context, target){
withGithubNotify(context: "${context}") {
withBeatsEnvWin(){
bat(label: "Mage ${target}", script: """
set
mage ${target}
""")
}
}
}
def withBeatsEnv(Closure body){
withEnv([
"HOME=${env.WORKSPACE}",
"GOPATH=${env.WORKSPACE}",
"PATH+GO=${env.WORKSPACE}/bin:${env.PATH}",
"MAGEFILE_CACHE=${WORKSPACE}\\.magefile",
"TEST_COVERAGE=true",
"RACE_DETECTOR=true",
]){
deleteDir()
unstash 'source'
dir("${BASE_DIR}"){
sh(label: "Install Go ${GO_VERSION}", script: ".ci/scripts/install-go.sh")
sh(label: "Install docker-compose ${DOCKER_COMPOSE_VERSION}", script: ".ci/scripts/install-docker-compose.sh")
try {
body()
} finally {
reportCoverage()
}
}
}
}
def withBeatsEnvWin(Closure body){
def goRoot = "${env.USERPROFILE}\\.gvm\\versions\\go${GO_VERSION}.windows.amd64"
withEnv([
"HOME=${WORKSPACE}",
"GOPATH=${WORKSPACE}",
"PATH+GO=${WORKSPACE}\\bin;${goRoot}\\bin;C:\\ProgramData\\chocolatey\\bin",
"MAGEFILE_CACHE=${WORKSPACE}\\.magefile",
"GOROOT=${goRoot}",
"TEST_COVERAGE=true",
"RACE_DETECTOR=true",
]){
deleteDir()
unstash 'source'
dir("${BASE_DIR}"){
bat(label: "Install Go ${GO_VERSION}", script: ".ci/scripts/install-tools.bat")
try {
body()
} finally {
catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') {
junit(allowEmptyResults: true, keepLongStdio: true, testResults: "**\\build\\TEST*.xml")
archiveArtifacts(allowEmptyArchive: true, artifacts: '**\\build\\TEST*.out')
}
}
}
}
}
def k8sTest(versions){
versions.each{ v ->
stage("k8s ${v}"){
withEnv(["K8S_VERSION=${v}"]){
withGithubNotify(context: "K8s ${v}") {
withBeatsEnv(){
sh(label: "Install k8s", script: """
eval "\$(gvm use ${GO_VERSION} --format=bash)"
.ci/scripts/kind-setup.sh
""")
sh(label: "Kubernetes Kind",script: "make KUBECONFIG=\"\$(kind get kubeconfig-path)\" -C deploy/kubernetes test")
sh(label: 'Delete cluster', script: 'kind delete cluster')
}
}
}
}
}
}
def reportCoverage(){
catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') {
junit(allowEmptyResults: true, keepLongStdio: true, testResults: "**/TEST-*.xml")
archiveArtifacts(allowEmptyArchive: true, artifacts: '**/TEST-*.out')
retry(2){
sh(label: 'Report to Codecov', script: '''
curl -sSLo codecov https://codecov.io/bash
for i in auditbeat filebeat heartbeat libbeat metricbeat packetbeat winlogbeat journalbeat
do
FILE="${i}/build/coverage/full.cov"
if [ -f "${FILE}" ]; then
bash codecov -f "${FILE}"
fi
done
''')
}
}
}
def isChanged(patterns){
return (
params.runAllStages
|| isGitRegionMatch(patterns: patterns, comparator: 'regexp')
)
}
def loadConfigEnvVars(){
env.BUILD_AUDITBEAT = isChanged(["^auditbeat/.*"])
env.BUILD_AUDITBEAT_XPACK = isChanged([
"^auditbeat/.*",
"^x-pack/auditbeat/.*",
"^x-pack/libbeat/.*",
])
env.BUILD_DOCKERLOGBEAT_XPACK = isChanged([
"^x-pack/dockerlogbeat/.*",
"^x-pack/libbeat/.*",
])
env.BUILD_DOCS = isChanged(
patterns: ["^docs/.*"],
comparator: 'regexp'
)
env.BUILD_FILEBEAT = isChanged(["^filebeat/.*"])
env.BUILD_FILEBEAT_XPACK = isChanged([
"^filebeat/.*",
"^x-pack/filebeat/.*",
"^x-pack/libbeat/.*",
])
env.BUILD_FUNCTIONBEAT_XPACK = isChanged([
"^x-pack/functionbeat/.*",
"^x-pack/libbeat/.*",
])
env.BUILD_GENERATOR = isChanged(["^generator/.*"])
env.BUILD_HEARTBEAT = isChanged(["^heartbeat/.*"])
env.BUILD_HEARTBEAT_XPACK = isChanged([
"^heartbeat/.*",
"^x-pack/heartbeat/.*",
"^x-pack/libbeat/.*",
])
env.BUILD_JOURNALBEAT = isChanged(["^journalbeat/.*"])
env.BUILD_JOURNALBEAT_XPACK = isChanged([
"^journalbeat/.*",
"^x-pack/journalbeat/.*",
"^x-pack/libbeat/.*",
])
env.BUILD_KUBERNETES = isChanged(["^deploy/kubernetes/*"])
env.BUILD_LIBBEAT = isChanged(
patterns: ["^libbeat/.*"],
comparator: 'regexp'
)
env.BUILD_LIBBEAT_XPACK = isChanged([
"^libbeat/.*",
"^x-pack/libbeat/.*",
])
env.BUILD_METRICBEAT = isChanged(["^metricbeat/.*"])
env.BUILD_METRICBEAT_XPACK = isChanged([
"^metricbeat/.*",
"^x-pack/libbeat/.*",
"^x-pack/metricbeat/.*",
])
env.BUILD_PACKETBEAT = isChanged(["^packetbeat/.*"])
env.BUILD_PACKETBEAT_XPACK = isChanged([
"^packetbeat/.*",
"^x-pack/libbeat/.*",
"^x-pack/packetbeat/.*",
])
env.BUILD_WINLOGBEAT = isChanged(["^winlogbeat/.*"])
env.BUILD_WINLOGBEAT_XPACK = isChanged([
"^winlogbeat/.*",
"^x-pack/libbeat/.*",
"^x-pack/winlogbeat/.*",
])
env.GO_VERSION = readFile(".go-version").trim()
}