-
-
Notifications
You must be signed in to change notification settings - Fork 370
/
Jenkinsfile
525 lines (511 loc) · 23.4 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
@Library('StanUtils')
import org.stan.Utils
def utils = new org.stan.Utils()
def skipRemainingStages = false
def skipOpenCL = false
def setupCXX(failOnError = true, CXX = CXX, String stanc3_bin_url = "nightly") {
errorStr = failOnError ? "-Werror " : ""
stanc3_bin_url_str = stanc3_bin_url != "nightly" ? "\nSTANC3_TEST_BIN_URL=${stanc3_bin_url}\n" : ""
writeFile(file: "make/local", text: "CXX=${CXX} -Wno-inconsistent-missing-override ${errorStr}${stanc3_bin_url_str}")
}
def runTests(String testPath, Boolean separateMakeStep=true) {
if (separateMakeStep) {
sh "python3 runTests.py -j${PARALLEL} ${testPath} --make-only"
}
try { sh "python3 runTests.py -j${PARALLEL} ${testPath}" }
finally { junit 'test/**/*.xml' }
}
def runTestsWin(String testPath, Boolean separateMakeStep=true) {
withEnv(['PATH+TBB=./lib/stan_math/lib/tbb']) {
if (separateMakeStep) {
bat """
SET \"PATH=C:\\Users\\jenkins\\Anaconda3;%PATH%\"
SET \"PATH=${env.RTOOLS40_HOME};%PATH%\"
SET \"PATH=${env.RTOOLS40_HOME}\\usr\\bin;${LLVM7}\\bin;%PATH%\" //
SET \"PATH=${env.RTOOLS40_HOME}\\mingw64\\bin;%PATH%\"
SET \"PATH=C:\\PROGRA~1\\R\\R-4.1.2\\bin;%PATH%\"
SET \"PATH=C:\\PROGRA~1\\Microsoft^ MPI\\Bin;%PATH%\"
SET \"MPI_HOME=C:\\PROGRA~1\\Microsoft^ MPI\\Bin\"
python runTests.py -j${PARALLEL} ${testPath} --make-only
"""
}
try {
bat """
SET \"PATH=C:\\Users\\jenkins\\Anaconda3;%PATH%\"
SET \"PATH=${env.RTOOLS40_HOME};%PATH%\"
SET \"PATH=${env.RTOOLS40_HOME}\\usr\\bin;${LLVM7}\\bin;%PATH%\" //
SET \"PATH=${env.RTOOLS40_HOME}\\mingw64\\bin;%PATH%\"
SET \"PATH=C:\\PROGRA~1\\R\\R-4.1.2\\bin;%PATH%\"
SET \"PATH=C:\\PROGRA~1\\Microsoft^ MPI\\Bin;%PATH%\"
SET \"MPI_HOME=C:\\PROGRA~1\\Microsoft^ MPI\\Bin\"
python runTests.py -j${PARALLEL} ${testPath}
"""
}
finally { junit 'test/**/*.xml' }
}
}
def deleteDirWin() {
bat "attrib -r -s /s /d"
deleteDir()
}
String stanc3_bin_url() { params.stanc3_bin_url ?: "nightly" }
String cmdstan_pr() { params.cmdstan_pr ?: "downstream_tests" }
String stan_pr() {
if (env.BRANCH_NAME == 'downstream_tests') {
''
} else if (env.BRANCH_NAME == 'downstream_hotfix') {
'master'
} else {
env.BRANCH_NAME
}
}
String integration_tests_flags() {
if (params.compile_all_model) {
'--no-ignore-models '
} else {
''
}
}
def isBranch(String b) { env.BRANCH_NAME == b }
Boolean isPR() { env.CHANGE_URL != null }
String fork() { env.CHANGE_FORK ?: "stan-dev" }
String branchName() { isPR() ? env.CHANGE_BRANCH :env.BRANCH_NAME }
pipeline {
agent none
parameters {
string(defaultValue: '', name: 'math_pr', description: "Leave blank "
+ "unless testing against a specific math repo pull request, "
+ "e.g. PR-640.")
string(defaultValue: 'downstream_tests', name: 'cmdstan_pr',
description: 'PR to test CmdStan upstream against e.g. PR-630')
string(defaultValue: 'nightly', name: 'stanc3_bin_url',
description: 'Custom stanc3 binary url')
booleanParam(defaultValue: false, name: 'run_tests_all_os', description: 'Run unit and integration tests on all OS.')
booleanParam(defaultValue: false, name: 'compile_all_models', description: 'Run integration tests on the full test model suite.')
}
options {
skipDefaultCheckout()
preserveStashes(buildCount: 7)
parallelsAlwaysFailFast()
buildDiscarder(logRotator(numToKeepStr: '20', daysToKeepStr: '30'))
disableConcurrentBuilds(abortPrevious: env.BRANCH_NAME != "downstream_tests" && env.BRANCH_NAME != "downstream_hotfix")
}
environment {
GCC = 'g++'
PARALLEL = 4
MAC_CXX = 'clang++'
LINUX_CXX = 'clang++-6.0'
WIN_CXX = 'g++'
GIT_AUTHOR_NAME = 'Stan Jenkins'
GIT_AUTHOR_EMAIL = 'mc.stanislaw@gmail.com'
GIT_COMMITTER_NAME = 'Stan Jenkins'
GIT_COMMITTER_EMAIL = 'mc.stanislaw@gmail.com'
OPENCL_DEVICE_ID_CPU = 0
OPENCL_DEVICE_ID_GPU = 0
OPENCL_PLATFORM_ID = 1
OPENCL_PLATFORM_ID_CPU = 0
OPENCL_PLATFORM_ID_GPU = 0
}
stages {
stage("Clang-format") {
agent {
docker {
image 'stanorg/ci:gpu'
label 'linux'
}
}
steps {
retry(3) { checkout scm }
withCredentials([usernamePassword(credentialsId: 'a630aebc-6861-4e69-b497-fd7f496ec46b',
usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD')]) {
sh """#!/bin/bash
set -x
git checkout -b ${branchName()}
clang-format --version
find src -name '*.hpp' -o -name '*.cpp' | xargs -n20 -P${PARALLEL} clang-format -i
if [[ `git diff` != "" ]]; then
git config user.email "mc.stanislaw@gmail.com"
git config user.name "Stan Jenkins"
git add src
git commit -m "[Jenkins] auto-formatting by `clang-format --version`"
git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/${fork()}/stan.git ${branchName()}
echo "Exiting build because clang-format found changes."
echo "Those changes are now found on stan-dev/stan under branch ${branchName()}"
echo "Please 'git pull' before continuing to develop."
exit 1
fi
"""
}
}
post {
always { deleteDir() }
failure {
script {
emailext (
subject: "[StanJenkins] Autoformattted: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: "Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' " +
"has been autoformatted and the changes committed " +
"to your branch, if permissions allowed." +
"Please pull these changes before continuing." +
"\n\n" +
"See https://github.com/stan-dev/stan/wiki/Coding-Style-and-Idioms" +
" for setting up the autoformatter locally.\n"+
"(Check console output at ${env.BUILD_URL})",
recipientProviders: [[$class: 'RequesterRecipientProvider']],
to: "${env.CHANGE_AUTHOR_EMAIL}"
)
}
}
}
}
stage('Linting & Doc checks') {
agent {
docker {
image 'stanorg/ci:gpu'
label 'linux'
}
}
steps {
script {
retry(3) { checkout scm }
sh """
make math-revert
make clean-all
git clean -xffd
"""
utils.checkout_pr("math", "lib/stan_math", params.math_pr)
stash 'StanSetup'
setupCXX(true, LINUX_CXX)
parallel(
CppLint: { sh "make cpplint" },
API_docs: { sh 'make doxygen' },
)
}
}
post {
always {
recordIssues(
id: "lint_doc_checks",
name: "Linting & Doc checks",
enabledForFailure: true,
aggregatingResults : true,
tools: [
cppLint(id: "cpplint", name: "Linting & Doc checks@CPPLINT")
],
qualityGates: [[threshold: 1, type: 'TOTAL', unstable: true]],
healthy: 10, unhealthy: 100, minimumSeverity: 'HIGH'
)
deleteDir()
}
}
}
stage('Verify changes') {
agent {
docker {
image 'stanorg/ci:gpu'
label 'linux'
}
}
steps {
script {
retry(3) { checkout scm }
sh 'git clean -xffd'
// These paths will be passed to git diff
// If there are changes to them, CI/CD will continue else skip
def paths = ['make', 'src/stan', 'src/test', 'Jenkinsfile', 'makefile', 'runTests.py',
'lib/stan_math/stan', 'lib/stan_math/make', 'lib/stan_math/lib', 'lib/stan_math/test',
'lib/stan_math/runTests.py', 'lib/stan_math/runChecks.py', 'lib/stan_math/makefile',
'lib/stan_math/Jenkinsfile', 'lib/stan_math/.clang-format'
].join(" ")
skipRemainingStages = utils.verifyChanges(paths)
def openCLPaths = ['src/stan/model/indexing'].join(" ")
skipOpenCL = utils.verifyChanges(openCLPaths)
}
}
post {
always {
deleteDir()
}
}
}
stage('Unit tests') {
when {
expression {
!skipRemainingStages
}
}
parallel {
stage('Windows Headers & Unit') {
agent { label 'windows' }
when {
expression {
!skipRemainingStages
}
}
steps {
deleteDirWin()
unstash 'StanSetup'
bat """
SET \"PATH=${env.RTOOLS40_HOME};%PATH%\"
SET \"PATH=${env.RTOOLS40_HOME}\\usr\\bin;${LLVM7}\\bin;%PATH%\" //
SET \"PATH=${env.RTOOLS40_HOME}\\mingw64\\bin;%PATH%\"
SET \"PATH=C:\\PROGRA~1\\R\\R-4.1.2\\bin;%PATH%\"
SET \"PATH=C:\\PROGRA~1\\Microsoft^ MPI\\Bin;%PATH%\"
SET \"MPI_HOME=C:\\PROGRA~1\\Microsoft^ MPI\\Bin\"
make.exe -f lib/stan_math/make/standalone math-libs
make.exe -j${PARALLEL} test-headers
"""
setupCXX(false, WIN_CXX, stanc3_bin_url())
runTestsWin("src/test/unit")
}
post { always { deleteDirWin() } }
}
stage('Linux Unit') {
agent {
docker {
image 'stanorg/ci:gpu'
label 'linux'
args '--pull always --gpus 1'
}
}
steps {
unstash 'StanSetup'
setupCXX(true, LINUX_CXX, stanc3_bin_url())
sh """
echo STAN_OPENCL=true > make/local
echo OPENCL_PLATFORM_ID=${OPENCL_PLATFORM_ID_GPU} >> make/local
echo OPENCL_DEVICE_ID=${OPENCL_DEVICE_ID_GPU} >> make/local
"""
sh """
make -j${PARALLEL} test-headers
"""
runTests("src/test/unit")
}
post { always { deleteDir() } }
}
stage('Mac Unit') {
agent { label 'osx' }
when {
expression {
( env.BRANCH_NAME == "develop" ||
env.BRANCH_NAME == "master" ||
params.run_tests_all_os ) &&
!skipRemainingStages
}
}
steps {
unstash 'StanSetup'
setupCXX(false, MAC_CXX, stanc3_bin_url())
runTests("src/test/unit")
}
post { always { deleteDir() } }
}
}
}
stage('Integration') {
when {
expression {
!skipRemainingStages
}
}
parallel {
stage('Integration Linux') {
agent {
docker {
image 'stanorg/ci:gpu'
label 'linux'
}
}
steps {
sh """
git clone --recursive https://github.com/stan-dev/performance-tests-cmdstan
git clone https://github.com/stan-dev/stanc3/ performance-tests-cmdstan/stanc3
"""
script {
if (params.cmdstan_pr != 'downstream_tests') {
if(params.cmdstan_pr.contains("PR-")){
pr_number = params.cmdstan_pr.split("-")[1]
sh """
cd performance-tests-cmdstan/cmdstan
git fetch origin pull/${pr_number}/head:pr/${pr_number}
git checkout pr/${pr_number}
"""
}else{
sh """
cd performance-tests-cmdstan/cmdstan
git checkout develop && git pull && git checkout ${params.cmdstan_pr}
"""
}
}
if (params.stanc3_bin_url != 'nightly') {
sh """
cd performance-tests-cmdstan/cmdstan
echo 'STANC3_TEST_BIN_URL=${params.stanc3_bin_url}' >> make/local
"""
}
}
dir('performance-tests-cmdstan/cmdstan/stan'){
unstash 'StanSetup'
script {
if (params.stanc3_bin_url != 'nightly') {
sh """
echo 'STANC3_TEST_BIN_URL=${params.stanc3_bin_url}' >> make/local
"""
}
}
}
sh """
cd performance-tests-cmdstan/cmdstan
echo 'O=0' >> make/local
echo 'CXX=${LINUX_CXX}' >> make/local
make clean-all
make -j${PARALLEL} build
cd ..
python3 ./runPerformanceTests.py -j${PARALLEL} ${integration_tests_flags()}--runs=0 stanc3/test/integration/good
python3 ./runPerformanceTests.py -j${PARALLEL} ${integration_tests_flags()}--runs=0 example-models
"""
sh """
cd performance-tests-cmdstan/cmdstan/stan
python3 ./runTests.py src/test/integration/compile_standalone_functions_test.cpp
python3 ./runTests.py src/test/integration/standalone_functions_test.cpp
python3 ./runTests.py src/test/integration/multiple_translation_units_test.cpp
"""
}
post { always { deleteDir() } }
}
stage('Integration Mac') {
agent { label 'osx' }
when {
expression {
( env.BRANCH_NAME == "develop" ||
env.BRANCH_NAME == "master" ||
params.run_tests_all_os ) &&
!skipRemainingStages
}
}
steps {
sh """
git clone --recursive https://github.com/stan-dev/performance-tests-cmdstan
"""
dir('performance-tests-cmdstan/cmdstan/stan'){
unstash 'StanSetup'
}
sh """
cd performance-tests-cmdstan/cmdstan
echo 'O=0' >> make/local
echo 'CXX=${MAC_CXX}' >> make/local
make clean-all
make -j${PARALLEL} build
cd ..
python3 ./runPerformanceTests.py -j${PARALLEL} ${integration_tests_flags()}--runs=0 stanc3/test/integration/good
python3 ./runPerformanceTests.py -j${PARALLEL} ${integration_tests_flags()}--runs=0 example-models
"""
sh """
cd performance-tests-cmdstan/cmdstan/stan
python3 ./runTests.py src/test/integration/compile_standalone_functions_test.cpp
python3 ./runTests.py src/test/integration/standalone_functions_test.cpp
python3 ./runTests.py src/test/integration/multiple_translation_units_test.cpp
"""
}
post { always { deleteDir() } }
}
stage('Integration Windows') {
agent { label 'windows' }
when {
expression {
!skipRemainingStages
}
}
steps {
deleteDirWin()
bat """
git clone --recursive https://github.com/stan-dev/performance-tests-cmdstan
"""
dir('performance-tests-cmdstan/cmdstan/stan'){
unstash 'StanSetup'
}
writeFile(file: "performance-tests-cmdstan/cmdstan/make/local", text: "CXX=${WIN_CXX}\nPRECOMPILED_HEADERS=true")
withEnv(["PATH+TBB=${WORKSPACE}\\performance-tests-cmdstan\\cmdstan\\stan\\lib\\stan_math\\lib\\tbb"]) {
bat """
SET \"PATH=C:\\Users\\jenkins\\Anaconda3;%PATH%\"
SET \"PATH=${env.RTOOLS40_HOME};%PATH%\"
SET \"PATH=${env.RTOOLS40_HOME}\\usr\\bin;${LLVM7}\\bin;%PATH%\" //
SET \"PATH=${env.RTOOLS40_HOME}\\mingw64\\bin;%PATH%\"
SET \"PATH=C:\\PROGRA~1\\R\\R-4.1.2\\bin;%PATH%\"
SET \"PATH=C:\\PROGRA~1\\Microsoft^ MPI\\Bin;%PATH%\"
SET \"MPI_HOME=C:\\PROGRA~1\\Microsoft^ MPI\\Bin\"
cd performance-tests-cmdstan/cmdstan
make.exe -j${PARALLEL} build
cd ..
python ./runPerformanceTests.py -j${PARALLEL} ${integration_tests_flags()}--runs=0 stanc3/test/integration/good
python ./runPerformanceTests.py -j${PARALLEL} ${integration_tests_flags()}--runs=0 example-models
"""
}
bat """
SET \"PATH=C:\\Users\\jenkins\\Anaconda3;%PATH%\"
SET \"PATH=${env.RTOOLS40_HOME};%PATH%\"
SET \"PATH=${env.RTOOLS40_HOME}\\usr\\bin;${LLVM7}\\bin;%PATH%\" //
SET \"PATH=${env.RTOOLS40_HOME}\\mingw64\\bin;%PATH%\"
SET \"PATH=C:\\PROGRA~1\\R\\R-4.1.2\\bin;%PATH%\"
SET \"PATH=C:\\PROGRA~1\\Microsoft^ MPI\\Bin;%PATH%\"
SET \"MPI_HOME=C:\\PROGRA~1\\Microsoft^ MPI\\Bin\"
cd performance-tests-cmdstan/cmdstan/stan
python ./runTests.py src/test/integration/compile_standalone_functions_test.cpp
python ./runTests.py src/test/integration/standalone_functions_test.cpp
python ./runTests.py src/test/integration/multiple_translation_units_test.cpp
"""
}
post { always { deleteDirWin() } }
}
}
}
stage('Upstream CmdStan tests') {
when {
expression {
( env.BRANCH_NAME ==~ /PR-\d+/ ||
env.BRANCH_NAME == "downstream_tests" ||
env.BRANCH_NAME == "downstream_hotfix" ) &&
!skipRemainingStages
}
}
steps {
build(job: "Stan/CmdStan/${cmdstan_pr()}",
parameters: [
string(name: 'stan_pr', value: stan_pr()),
string(name: 'math_pr', value: params.math_pr),
string(name: 'stanc3_bin_url', value: stanc3_bin_url())
])
}
}
}
// Below lines are commented to avoid spamming emails during migration/debug
post {
always {
node("linux") {
recordIssues(
id: "pipeline",
name: "Entire pipeline results",
enabledForFailure: true,
aggregatingResults : false,
filters: [
excludeFile('lib/.*')
],
tools: [
gcc4(id: "pipeline_gcc4", name: "GNU C Compiler"),
clang(id: "pipeline_clang", name: "LLVM/Clang")
],
qualityGates: [[threshold: 30, type: 'TOTAL', unstable: true]],
healthy: 10, unhealthy: 100, minimumSeverity: 'HIGH'
)
}
}
success {
script {
utils.updateUpstream(env,'cmdstan')
utils.mailBuildResults("SUCCESSFUL")
}
}
unstable { script { utils.mailBuildResults("UNSTABLE", "stan-buildbot@googlegroups.com") } }
failure { script { utils.mailBuildResults("FAILURE", "stan-buildbot@googlegroups.com") } }
}
}