forked from elastic/apm-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
436 lines (433 loc) · 14.6 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
#!/usr/bin/env groovy
@Library('apm@current') _
pipeline {
agent any
environment {
REPO = 'apm-server'
BASE_DIR = "src/github.com/elastic/${env.REPO}"
NOTIFY_TO = credentials('notify-to')
JOB_GCS_BUCKET = credentials('gcs-bucket')
JOB_GCS_CREDENTIALS = 'apm-ci-gcs-plugin'
CODECOV_SECRET = 'secret/apm-team/ci/apm-server-codecov'
GITHUB_CHECK_ITS_NAME = 'Integration Tests'
ITS_PIPELINE = 'apm-integration-tests-selector-mbp/master'
}
options {
timeout(time: 2, unit: 'HOURS')
buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20', daysToKeepStr: '30'))
timestamps()
ansiColor('xterm')
disableResume()
durabilityHint('PERFORMANCE_OPTIMIZED')
rateLimitBuilds(throttle: [count: 60, durationName: 'hour', userBoost: true])
quietPeriod(10)
}
triggers {
issueCommentTrigger('(?i).*(?:jenkins\\W+)?run\\W+(?:the\\W+)?tests(?:\\W+please)?.*')
}
parameters {
booleanParam(name: 'Run_As_Master_Branch', defaultValue: false, description: 'Allow to run any steps on a PR, some steps normally only run on master branch.')
booleanParam(name: 'linux_ci', defaultValue: true, description: 'Enable Linux build')
booleanParam(name: 'windows_ci', defaultValue: true, description: 'Enable Windows CI')
booleanParam(name: 'intake_ci', defaultValue: true, description: 'Enable test')
booleanParam(name: 'test_ci', defaultValue: true, description: 'Enable test')
booleanParam(name: 'test_sys_env_ci', defaultValue: true, description: 'Enable system and environment test')
booleanParam(name: 'bench_ci', defaultValue: true, description: 'Enable benchmarks')
booleanParam(name: 'release_ci', defaultValue: true, description: 'Enable build the release packages')
booleanParam(name: 'kibana_update_ci', defaultValue: true, description: 'Enable build the Check kibana Obj. Updated')
booleanParam(name: 'its_ci', defaultValue: true, description: 'Enable async ITs')
}
stages {
/**
Checkout the code and stash it, to use it on other stages.
*/
stage('Checkout') {
agent { label 'master || immutable' }
environment {
PATH = "${env.PATH}:${env.WORKSPACE}/bin"
HOME = "${env.WORKSPACE}"
GOPATH = "${env.WORKSPACE}"
}
options { skipDefaultCheckout() }
steps {
deleteDir()
gitCheckout(basedir: "${BASE_DIR}", githubNotifyFirstTimeContributor: true)
stash allowEmpty: true, name: 'source', useDefaultExcludes: false
script {
dir("${BASE_DIR}"){
env.GO_VERSION = readFile(".go-version").trim()
def regexps =[
"^_beats",
"^apm-server.yml",
"^apm-server.docker.yml",
"^magefile.go",
"^ingest",
"^packaging",
"^tests/packaging",
"^vendor/github.com/elastic/beats"
]
env.BEATS_UPDATED = isGitRegionMatch(regexps: regexps)
}
}
}
}
/**
Updating generated files for Beat.
Checks the GO environment.
Checks the Python environment.
Checks YAML files are generated.
Validate that all updates were committed.
*/
stage('Intake') {
agent { label 'linux && immutable' }
options { skipDefaultCheckout() }
environment {
PATH = "${env.PATH}:${env.WORKSPACE}/bin"
HOME = "${env.WORKSPACE}"
GOPATH = "${env.WORKSPACE}"
}
when {
beforeAgent true
expression { return params.intake_ci }
}
steps {
withGithubNotify(context: 'Intake') {
deleteDir()
unstash 'source'
dir("${BASE_DIR}"){
sh(label: 'Run intake', script: './script/jenkins/intake.sh')
}
}
}
}
stage('Build'){
failFast false
parallel {
/**
Build on a linux environment.
*/
stage('linux build') {
agent { label 'linux && immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression { return params.linux_ci }
}
steps {
withGithubNotify(context: 'Build - Linux') {
deleteDir()
unstash 'source'
golang(){
dir(BASE_DIR){
retry(2) { // Retry in case there are any errors to avoid temporary glitches
sleep randomNumber(min: 5, max: 10)
sh(label: 'Linux build', script: './script/jenkins/build.sh')
}
}
}
}
}
}
/**
Build on a windows environment.
*/
stage('windows build') {
agent { label 'windows-2019-immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression { return params.windows_ci }
}
steps {
withGithubNotify(context: 'Build - Windows') {
deleteDir()
unstash 'source'
dir(BASE_DIR){
retry(2) { // Retry in case there are any errors to avoid temporary glitches
sleep randomNumber(min: 5, max: 10)
powershell(label: 'Windows build', script: '.\\script\\jenkins\\windows-build.ps1')
}
}
}
}
}
}
}
stage('Test') {
failFast false
parallel {
/**
Run unit tests and report junit results.
*/
stage('Unit Test') {
agent { label 'linux && immutable' }
options { skipDefaultCheckout() }
environment {
PATH = "${env.PATH}:${env.WORKSPACE}/bin"
HOME = "${env.WORKSPACE}"
GOPATH = "${env.WORKSPACE}"
}
when {
beforeAgent true
expression { return params.test_ci }
}
steps {
withGithubNotify(context: 'Unit Tests', tab: 'tests') {
deleteDir()
unstash 'source'
dir("${BASE_DIR}"){
sh(label: 'Run Unit tests', script: './script/jenkins/unit-test.sh')
}
}
}
post {
always {
junit(allowEmptyResults: true,
keepLongStdio: true,
testResults: "${BASE_DIR}/build/junit-*.xml")
}
}
}
/**
Runs System and Environment Tests, then generate coverage and unit test reports.
Finally archive the results.
*/
stage('System and Environment Tests') {
agent { label 'linux && immutable' }
options { skipDefaultCheckout() }
environment {
PATH = "${env.PATH}:${env.WORKSPACE}/bin"
HOME = "${env.WORKSPACE}"
GOPATH = "${env.WORKSPACE}"
}
when {
beforeAgent true
expression { return params.test_sys_env_ci }
}
steps {
withGithubNotify(context: 'System Tests', tab: 'tests') {
deleteDir()
unstash 'source'
dir("${BASE_DIR}"){
sh(label: 'Run Linux tests', script: './script/jenkins/linux-test.sh')
}
}
}
post {
always {
coverageReport("${BASE_DIR}/build/coverage")
junit(allowEmptyResults: true,
keepLongStdio: true,
testResults: "${BASE_DIR}/build/junit-*.xml,${BASE_DIR}/build/TEST-*.xml"
)
catchError(buildResult: 'SUCCESS', message: 'Failed to grab test results tar files', stageResult: 'SUCCESS') {
tar(file: "system-tests-linux-files.tgz", archive: true, dir: "system-tests", pathPrefix: "${BASE_DIR}/build")
tar(file: "coverage-files.tgz", archive: true, dir: "coverage", pathPrefix: "${BASE_DIR}/build")
}
codecov(repo: env.REPO, basedir: "${BASE_DIR}", secret: "${CODECOV_SECRET}")
}
}
}
/**
Run tests on a windows environment.
Finally archive the results.
*/
stage('windows test') {
agent { label 'windows-2019-immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
expression { return params.windows_ci }
}
steps {
withGithubNotify(context: 'Test - Windows', tab: 'tests') {
deleteDir()
unstash 'source'
dir("${BASE_DIR}"){
powershell(label: 'Run Window tests', script: '.\\script\\jenkins\\windows-test.ps1')
}
}
}
post {
always {
junit(allowEmptyResults: true,
keepLongStdio: true,
testResults: "${BASE_DIR}/build/junit-report.xml,${BASE_DIR}/build/TEST-*.xml")
}
}
}
/**
Runs benchmarks on the current version and compare it with the previous ones.
Finally archive the results.
*/
stage('Benchmarking') {
agent { label 'linux && immutable' }
options { skipDefaultCheckout() }
when {
beforeAgent true
allOf {
anyOf {
branch 'master'
branch "\\d+\\.\\d+"
branch "v\\d?"
tag "v\\d+\\.\\d+\\.\\d+*"
expression { return params.Run_As_Master_Branch }
}
expression { return params.bench_ci }
}
}
steps {
withGithubNotify(context: 'Benchmarking') {
deleteDir()
unstash 'source'
golang(){
dir("${BASE_DIR}"){
sh(label: 'Run benchmarks', script: './script/jenkins/bench.sh')
sendBenchmarks(file: 'bench.out', index: "benchmark-server")
}
}
}
}
}
/**
updates beats updates the framework part and go parts of beats.
Then build and test.
Finally archive the results.
*/
/*
stage('Update Beats') {
agent { label 'linux' }
steps {
ansiColor('xterm') {
deleteDir()
dir("${BASE_DIR}"){
unstash 'source'
sh """
#!
./script/jenkins/update-beats.sh
"""
archiveArtifacts allowEmptyArchive: true, artifacts: "${BASE_DIR}/build", onlyIfSuccessful: false
}
}
}
}*/
}
}
/**
Checks if kibana objects are updated.
*/
stage('Check kibana Obj. Updated') {
agent { label 'linux && immutable' }
options { skipDefaultCheckout() }
environment {
PATH = "${env.PATH}:${env.WORKSPACE}/bin"
HOME = "${env.WORKSPACE}"
GOPATH = "${env.WORKSPACE}"
}
when {
beforeAgent true
expression { return params.kibana_update_ci }
}
steps {
withGithubNotify(context: 'Sync Kibana') {
deleteDir()
unstash 'source'
dir("${BASE_DIR}"){
catchError(buildResult: 'SUCCESS', message: 'Sync Kibana is not updated', stageResult: 'UNSTABLE') {
sh(label: 'Test Sync', script: './script/jenkins/sync.sh')
}
}
}
}
}
stage('Integration Tests') {
agent none
when {
beforeAgent true
allOf {
anyOf {
environment name: 'GIT_BUILD_CAUSE', value: 'pr'
expression { return !params.Run_As_Master_Branch }
}
expression { return params.its_ci }
}
}
steps {
log(level: 'INFO', text: 'Launching Async ITs')
build(job: env.ITS_PIPELINE, propagate: false, wait: false,
parameters: [string(name: 'AGENT_INTEGRATION_TEST', value: 'All'),
string(name: 'BUILD_OPTS', value: "--apm-server-build https://github.com/elastic/${env.REPO}@${env.GIT_BASE_COMMIT}"),
string(name: 'GITHUB_CHECK_NAME', value: env.GITHUB_CHECK_ITS_NAME),
string(name: 'GITHUB_CHECK_REPO', value: env.REPO),
string(name: 'GITHUB_CHECK_SHA1', value: env.GIT_BASE_COMMIT)])
githubNotify(context: "${env.GITHUB_CHECK_ITS_NAME}", description: "${env.GITHUB_CHECK_ITS_NAME} ...", status: 'PENDING', targetUrl: "${env.JENKINS_URL}search/?q=${env.ITS_PIPELINE.replaceAll('/','+')}")
}
}
/**
build release packages.
*/
stage('Release') {
agent { label 'linux && immutable' }
options { skipDefaultCheckout() }
environment {
PATH = "${env.PATH}:${env.WORKSPACE}/bin"
HOME = "${env.WORKSPACE}"
GOPATH = "${env.WORKSPACE}"
SNAPSHOT="true"
}
when {
beforeAgent true
allOf {
anyOf {
branch 'master'
branch "\\d+\\.\\d+"
branch "v\\d?"
tag "v\\d+\\.\\d+\\.\\d+*"
expression { return params.Run_As_Master_Branch }
expression { return env.BEATS_UPDATED != "false" }
}
expression { return params.release_ci }
}
}
steps {
withGithubNotify(context: 'Release') {
deleteDir()
unstash 'source'
/**
The package build needs mage and docker
*/
golang(){
dir("${BASE_DIR}"){
sh(label: 'Build packages', script: './script/jenkins/package.sh')
sh(label: 'Test packages install', script: './script/jenkins/test-install-packages.sh')
}
}
}
}
post {
success {
echo "Archive packages"
googleStorageUpload(bucket: "gs://${JOB_GCS_BUCKET}/snapshots",
credentialsId: "${JOB_GCS_CREDENTIALS}",
pathPrefix: "${BASE_DIR}/build/distributions/",
pattern: "${BASE_DIR}/build/distributions/**/*",
sharedPublicly: true,
showInline: true)
}
}
}
}
post {
cleanup {
notifyBuildResult()
}
}
}
def golang(Closure body){
def golangDocker = docker.build("golang-mage", "--build-arg GO_VERSION=${GO_VERSION} ${BASE_DIR}/.ci/docker/golang-mage")
withEnv(["HOME=${WORKSPACE}", "GOPATH=${WORKSPACE}", "SHELL=/bin/bash"]) {
golangDocker.inside('-v /usr/bin/docker:/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock'){
body()
}
}
}