forked from elastic/apm-agent-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
409 lines (403 loc) · 16.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
#!/usr/bin/env groovy
@Library('apm@current') _
pipeline {
agent { label 'linux && immutable' }
environment {
REPO = 'apm-agent-dotnet'
// keep it short to avoid the 248 characters PATH limit in Windows
BASE_DIR = "apm-agent-dotnet"
NOTIFY_TO = credentials('notify-to')
JOB_GCS_BUCKET = credentials('gcs-bucket')
CODECOV_SECRET = 'secret/apm-team/ci/apm-agent-dotnet-codecov'
GITHUB_CHECK_ITS_NAME = 'Integration Tests'
ITS_PIPELINE = 'apm-integration-tests-selector-mbp/master'
}
options {
timeout(time: 1, 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.')
}
stages {
stage('Initializing'){
stages{
stage('Checkout') {
options { skipDefaultCheckout() }
steps {
deleteDir()
gitCheckout(basedir: "${BASE_DIR}", githubNotifyFirstTimeContributor: true)
stash allowEmpty: true, name: 'source', useDefaultExcludes: false
}
}
stage('Parallel'){
parallel{
stage('Linux'){
options { skipDefaultCheckout() }
environment {
MSBUILDDEBUGPATH = "${env.WORKSPACE}"
}
/**
Make sure there are no code style violation in the repo.
*/
stages{
// Disable until https://github.com/elastic/apm-agent-dotnet/issues/563
// stage('CodeStyleCheck') {
// steps {
// withGithubNotify(context: 'CodeStyle check') {
// deleteDir()
// unstash 'source'
// dir("${BASE_DIR}"){
// dotnet(){
// sh label: 'Install and run dotnet/format', script: '.ci/linux/codestyle.sh'
// }
// }
// }
// }
// }
/**
Build the project from code..
*/
stage('Build') {
steps {
withGithubNotify(context: 'Build - Linux') {
deleteDir()
unstash 'source'
dir("${BASE_DIR}"){
dotnet(){
sh '.ci/linux/build.sh'
}
}
}
}
post {
unsuccessful {
archiveArtifacts(allowEmptyArchive: true,
artifacts: "${MSBUILDDEBUGPATH}/**/MSBuild_*.failure.txt")
}
}
}
/**
Execute unit tests.
*/
stage('Test') {
steps {
withGithubNotify(context: 'Test - Linux', tab: 'tests') {
deleteDir()
unstash 'source'
dir("${BASE_DIR}"){
dotnet(){
sh label: 'Install test tools', script: '.ci/linux/test-tools.sh'
sh label: 'Build', script: '.ci/linux/build.sh'
sh label: 'Test & coverage', script: '.ci/linux/test.sh'
sh label: 'Convert Test Results to junit format', script: '.ci/linux/convert.sh'
}
}
}
}
post {
always {
sh label: 'debugging', script: 'find . -name *.pdb'
junit(allowEmptyResults: true,
keepLongStdio: true,
testResults: "${BASE_DIR}/**/junit-*.xml,${BASE_DIR}/target/**/TEST-*.xml")
codecov(repo: env.REPO, basedir: "${BASE_DIR}", secret: "${CODECOV_SECRET}")
}
unsuccessful {
archiveArtifacts(allowEmptyArchive: true,
artifacts: "${MSBUILDDEBUGPATH}/**/MSBuild_*.failure.txt")
}
}
}
}
}
stage('Windows .NET Framework'){
agent { label 'windows-2019-immutable' }
options { skipDefaultCheckout() }
environment {
HOME = "${env.WORKSPACE}"
DOTNET_ROOT = "${env.WORKSPACE}\\dotnet"
VS_HOME = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise"
PATH = "${env.DOTNET_ROOT};${env.DOTNET_ROOT}\\tools;${env.PATH};${env.HOME}\\bin;\"${env.VS_HOME}\\MSBuild\\15.0\\Bin\""
MSBUILDDEBUGPATH = "${env.WORKSPACE}"
}
stages{
/**
Checkout the code and stash it, to use it on other stages.
*/
stage('Install tools') {
steps {
cleanDir("${WORKSPACE}/*")
unstash 'source'
dir("${HOME}"){
powershell label: 'Install tools', script: "${BASE_DIR}\\.ci\\windows\\tools.ps1"
}
}
}
/**
Build the project from code..
*/
stage('Build - MSBuild') {
steps {
withGithubNotify(context: 'Build MSBuild - Windows') {
cleanDir("${WORKSPACE}/${BASE_DIR}")
unstash 'source'
dir("${BASE_DIR}"){
bat '.ci/windows/msbuild.bat'
}
}
}
post {
unsuccessful {
archiveArtifacts(allowEmptyArchive: true,
artifacts: "${MSBUILDDEBUGPATH}/**/MSBuild_*.failure.txt")
}
}
}
/**
Execute unit tests.
*/
stage('Test') {
steps {
withGithubNotify(context: 'Test MSBuild - Windows', tab: 'tests') {
cleanDir("${WORKSPACE}/${BASE_DIR}")
unstash 'source'
dir("${BASE_DIR}"){
powershell label: 'Install test tools', script: '.ci\\windows\\test-tools.ps1'
bat label: 'Build', script: '.ci/windows/msbuild.bat'
bat label: 'Test & coverage', script: '.ci/windows/test.bat'
powershell label: 'Convert Test Results to junit format', script: '.ci\\windows\\convert.ps1'
}
}
}
post {
always {
junit(allowEmptyResults: true,
keepLongStdio: true,
testResults: "${BASE_DIR}/**/junit-*.xml,${BASE_DIR}/target/**/TEST-*.xml")
}
unsuccessful {
archiveArtifacts(allowEmptyArchive: true,
artifacts: "${MSBUILDDEBUGPATH}/**/MSBuild_*.failure.txt")
}
}
}
/**
Execute IIS tests.
*/
stage('IIS Tests') {
steps {
withGithubNotify(context: 'IIS Tests', tab: 'tests') {
cleanDir("${WORKSPACE}/${BASE_DIR}")
unstash 'source'
dir("${BASE_DIR}"){
bat label: 'Build', script: '.ci/windows/msbuild.bat'
bat label: 'Test IIS', script: '.ci/windows/test-iis.bat'
powershell label: 'Convert Test Results to junit format', script: '.ci\\windows\\convert.ps1'
}
}
}
post {
always {
junit(allowEmptyResults: true,
keepLongStdio: true,
testResults: "${BASE_DIR}/**/junit-*.xml,${BASE_DIR}/target/**/TEST-*.xml")
}
}
}
}
post {
always {
cleanWs(disableDeferredWipeout: true, notFailBuild: true)
}
}
}
stage('Windows .NET Core'){
agent { label 'windows-2019-immutable' }
options { skipDefaultCheckout() }
environment {
HOME = "${env.WORKSPACE}"
DOTNET_ROOT = "${env.WORKSPACE}\\dotnet"
VS_HOME = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise"
PATH = "${env.DOTNET_ROOT};${env.DOTNET_ROOT}\\tools;${env.PATH};${env.HOME}\\bin;\"${env.VS_HOME}\\MSBuild\\15.0\\Bin\""
MSBUILDDEBUGPATH = "${env.WORKSPACE}"
}
stages{
/**
Checkout the code and stash it, to use it on other stages.
*/
stage('Install tools') {
steps {
cleanDir("${WORKSPACE}/*")
unstash 'source'
dir("${HOME}"){
powershell label: 'Install tools', script: "${BASE_DIR}\\.ci\\windows\\tools.ps1"
}
}
}
/**
Build the project from code..
*/
stage('Build - dotnet') {
steps {
withGithubNotify(context: 'Build dotnet - Windows') {
cleanDir("${WORKSPACE}/${BASE_DIR}")
unstash 'source'
dir("${BASE_DIR}"){
bat '.ci/windows/dotnet.bat'
}
}
}
post {
unsuccessful {
archiveArtifacts(allowEmptyArchive: true,
artifacts: "${MSBUILDDEBUGPATH}/**/MSBuild_*.failure.txt")
}
}
}
/**
Execute unit tests.
*/
stage('Test') {
steps {
withGithubNotify(context: 'Test dotnet - Windows', tab: 'tests') {
cleanDir("${WORKSPACE}/${BASE_DIR}")
unstash 'source'
dir("${BASE_DIR}"){
powershell label: 'Install test tools', script: '.ci\\windows\\test-tools.ps1'
bat label: 'Build', script: '.ci/windows/dotnet.bat'
bat label: 'Test & coverage', script: '.ci/windows/test.bat'
powershell label: 'Convert Test Results to junit format', script: '.ci\\windows\\convert.ps1'
}
}
}
post {
always {
junit(allowEmptyResults: true,
keepLongStdio: true,
testResults: "${BASE_DIR}/**/junit-*.xml,${BASE_DIR}/target/**/TEST-*.xml")
}
unsuccessful {
archiveArtifacts(allowEmptyArchive: true,
artifacts: "${MSBUILDDEBUGPATH}/**/MSBuild_*.failure.txt")
}
}
}
}
post {
always {
cleanWs(disableDeferredWipeout: true, notFailBuild: true)
}
}
}
}
}
stage('Release to AppVeyor') {
options { skipDefaultCheckout() }
when {
beforeAgent true
anyOf {
branch 'master'
expression { return params.Run_As_Master_Branch }
}
}
steps {
withGithubNotify(context: 'Release AppVeyor', tab: 'artifacts') {
deleteDir()
unstash 'source'
dir("${BASE_DIR}"){
release('secret/apm-team/ci/elastic-observability-appveyor')
}
}
}
post{
success {
archiveArtifacts(allowEmptyArchive: true,
artifacts: "${BASE_DIR}/**/bin/Release/**/*.nupkg")
}
}
}
stage('Release to NuGet') {
options { skipDefaultCheckout() }
when {
beforeAgent true
anyOf {
tag "\\d+\\.\\d+\\.\\d+*"
expression { return params.Run_As_Master_Branch }
}
}
steps {
input(message: 'Should we release a new version on NuGet?', ok: 'Yes, we should.')
withGithubNotify(context: 'Release NuGet', tab: 'artifacts') {
deleteDir()
unstash 'source'
dir("${BASE_DIR}"){
release('secret/apm-team/ci/elastic-observability-nuget')
}
}
}
}
stage('Integration Tests') {
agent none
when {
beforeAgent true
allOf {
anyOf {
environment name: 'GIT_BUILD_CAUSE', value: 'pr'
expression { return !params.Run_As_Master_Branch }
}
}
}
steps {
log(level: 'INFO', text: 'Launching Async ITs')
// TODO: use commit rather than branch to be reproducible.
build(job: env.ITS_PIPELINE, propagate: false, wait: false,
parameters: [string(name: 'AGENT_INTEGRATION_TEST', value: '.NET'),
string(name: 'BUILD_OPTS', value: "--dotnet-agent-version ${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('/','+')}")
}
}
}
}
}
post {
cleanup {
notifyBuildResult()
}
}
}
def cleanDir(path){
powershell label: "Clean ${path}", script: "Remove-Item -Recurse -Force ${path}"
}
def dotnet(Closure body){
def home = "/tmp"
def dotnetRoot = "/${home}/.dotnet"
def path = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/${home}/bin:${dotnetRoot}:${dotnetRoot}/bin:${dotnetRoot}/tools"
docker.image('mcr.microsoft.com/dotnet/core/sdk:2.1.505').inside("-e HOME='${home}' -e PATH='${path}'"){
body()
}
}
def release(secret){
dotnet(){
sh(label: 'Release', script: '.ci/linux/release.sh')
def repo = getVaultSecret(secret: secret)
wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [
[var: 'REPO_API_KEY', password: repo.apiKey],
[var: 'REPO_API_URL', password: repo.url],
]]) {
sh(label: 'Deploy', script: ".ci/linux/deploy.sh ${repo.data.apiKey} ${repo.data.url}")
}
}
}