-
-
Notifications
You must be signed in to change notification settings - Fork 93
/
Jenkinsfile
401 lines (378 loc) · 16.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
@Library('StanUtils')
import org.stan.Utils
def utils = new org.stan.Utils()
def skipRemainingStages = false
def setupCXX(CXX = env.CXX) {
unstash 'CmdStanSetup'
stanc3_bin_url_str = params.stanc3_bin_url != "nightly" ? "\nSTANC3_TEST_BIN_URL=${params.stanc3_bin_url}\n" : ""
writeFile(file: "make/local", text: "CXX=${CXX} \n${stanc3_bin_url_str} \nCXXFLAGS+=-Wp,-D_GLIBCXX_ASSERTIONS\n")
}
def runTests(String prefix = "") {
""" make -j${env.PARALLEL} build
${prefix}runCmdStanTests.py -j${env.PARALLEL} src/test/interface
"""
}
def runWinTests(String prefix = "") {
withEnv(["PATH+TBB=${WORKSPACE}\\stan\\lib\\stan_math\\lib\\tbb"]) {
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\"
SET \"PATH=C:\\Users\\jenkins\\Anaconda3;%PATH%\"
make -j${env.PARALLEL} build
python ${prefix}runCmdStanTests.py -j${env.PARALLEL} src/test/interface
"""
}
}
def deleteDirWin() {
bat "attrib -r -s /s /d"
deleteDir()
}
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
options {
skipDefaultCheckout()
disableConcurrentBuilds(abortPrevious: env.BRANCH_NAME != "downstream_tests" && env.BRANCH_NAME != "downstream_hotfix")
}
parameters {
string(defaultValue: '', name: 'stan_pr',
description: "Stan PR to test against. Will check out this PR in the downstream Stan repo.")
string(defaultValue: '', name: 'math_pr',
description: "Math PR to test against. Will check out this PR in the downstream Math repo.")
string(defaultValue: 'nightly', name: 'stanc3_bin_url',
description: 'Custom stanc3 binary url')
}
environment {
MAC_CXX = 'clang++'
LINUX_CXX = 'clang++-6.0'
WIN_CXX = 'g++'
PARALLEL = 8
MPICXX = 'mpicxx.openmpi'
GIT_AUTHOR_NAME = 'Stan Jenkins'
GIT_AUTHOR_EMAIL = '[email protected]'
GIT_COMMITTER_NAME = 'Stan Jenkins'
GIT_COMMITTER_EMAIL = '[email protected]'
}
stages {
stage('Clean & Setup') {
agent {
docker {
image 'stanorg/ci:gpu'
label 'linux'
}
}
steps {
retry(3) { checkout scm }
sh 'git clean -xffd'
sh 'make stan-revert'
script {
utils.checkout_pr("stan", "stan", params.stan_pr)
utils.checkout_pr("math", "stan/lib/stan_math", params.math_pr)
}
stash 'CmdStanSetup'
}
post { always { deleteDir() }}
}
stage('Verify changes') {
agent {
docker {
image 'stanorg/ci:gpu'
label 'linux'
}
}
steps {
script {
retry(3) { checkout scm }
sh 'git clean -xffd'
def paths = ['src/cmdstan', 'src/test', 'lib', 'examples', 'make', 'stan', 'install-tbb.bat', 'makefile', 'runCmdStanTests.py', 'test-all.sh', 'Jenkinsfile'].join(" ")
skipRemainingStages = utils.verifyChanges(paths)
}
}
post {
always {
deleteDir()
}
}
}
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${env.PARALLEL} clang-format -i
if [[ `git diff` != "" ]]; then
git add src
git commit -m "[Jenkins] auto-formatting by `clang-format --version`"
git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/${fork()}/cmdstan.git ${branchName()}
echo "Exiting build because clang-format found changes."
echo "Those changes are now found on stan-dev/cmdstan 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('Parallel tests') {
when {
expression {
!skipRemainingStages
}
}
parallel {
stage('Windows interface tests') {
agent { label 'windows' }
steps {
setupCXX(WIN_CXX)
runWinTests()
}
post {
always {
recordIssues(
id: "Windows",
name: "Windows interface tests",
enabledForFailure: true,
aggregatingResults : false,
filters: [
excludeFile('/lib/.*'),
excludeFile('tbb/*'),
excludeFile('stan/lib/stan_math/lib/*'),
excludeMessage(".*'sprintf' is deprecated.*")
],
tools: [
gcc4(id: "Windows_gcc4", name: "Windows interface tests@GCC4"),
clang(id: "Windows_clang", name: "Windows interface tests@CLANG")
],
qualityGates: [[threshold: 1, type: 'TOTAL', unstable: true]],
healthy: 10, unhealthy: 100, minimumSeverity: 'HIGH'
)
deleteDirWin()
}
}
}
stage('Linux interface tests with MPI') {
agent {
docker {
image 'stanorg/ci:gpu'
label 'linux'
}
}
steps {
setupCXX(MPICXX)
sh "echo STAN_MPI=true >> make/local"
sh "echo CXX_TYPE=gcc >> make/local"
sh "make build-mpi > build-mpi.log 2>&1"
sh runTests("./")
}
post {
always {
recordIssues(
id: "Linux_mpi",
name: "Linux interface tests with MPI",
enabledForFailure: true,
aggregatingResults : false,
filters: [
excludeFile('/lib/.*'),
excludeFile('tbb/*'),
excludeFile('stan/lib/stan_math/lib/*'),
excludeMessage(".*'sprintf' is deprecated.*")
],
tools: [
gcc4(id: "Linux_mpi_gcc4", name: "Linux interface tests with MPI@GCC4"),
clang(id: "Linux_mpi_clang", name: "Linux interface tests with MPI@CLANG")
],
qualityGates: [[threshold: 1, type: 'TOTAL', unstable: true]],
healthy: 10, unhealthy: 100, minimumSeverity: 'HIGH'
)
deleteDir()
}
}
}
stage('Mac interface tests') {
agent { label 'osx' }
steps {
setupCXX(MAC_CXX)
sh runTests("python3 ./")
}
post {
always {
recordIssues(
id: "Mac",
name: "Mac interface tests",
enabledForFailure: true,
aggregatingResults : false,
filters: [
excludeFile('/lib/.*'),
excludeFile('tbb/*'),
excludeFile('stan/lib/stan_math/lib/*'),
excludeMessage(".*'sprintf' is deprecated.*")
],
tools: [
gcc4(id: "Mac_gcc4", name: "Mac interface tests@GCC4"),
clang(id: "Mac_clang", name: "Mac interface tests@CLANG")
],
qualityGates: [[threshold: 1, type: 'TOTAL', unstable: true]],
healthy: 10, unhealthy: 100, minimumSeverity: 'HIGH'
)
deleteDir()
}
}
}
stage('Upstream CmdStan Performance tests') {
when {
expression {
env.BRANCH_NAME ==~ /PR-\d+/ ||
env.BRANCH_NAME == "downstream_tests" ||
env.BRANCH_NAME == "downstream_hotfix"
}
}
steps {
script{
build(
job: "Stan/CmdStan Performance Tests/downstream_tests",
parameters: [
string(name: 'cmdstan_pr', value: env.BRANCH_NAME),
string(name: 'stan_pr', value: params.stan_pr),
string(name: 'math_pr', value: params.math_pr),
string(name: 'stanc3_bin_url', value: params.stanc3_bin_url)
],
wait:true
)
}
}
}
}
}
stage('Update downstream branches') {
parallel {
stage('Update downstream_hotfix - master') {
agent {
docker {
image 'ellerbrock/alpine-bash-git'
label 'linux'
args '--entrypoint='
}
}
when {
beforeAgent true
branch 'master'
}
steps {
script {
retry(3) {
checkout([
$class: 'GitSCM',
branches: [[name: '*/master'], [name: '*/downstream_hotfix']],
userRemoteConfigs: scm.userRemoteConfigs
])
}
withCredentials([usernamePassword(credentialsId: 'a630aebc-6861-4e69-b497-fd7f496ec46b',
usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD')]) {
sh """#!/bin/bash
set -x
git checkout downstream_hotfix
git reset --hard origin/master
git status
git push -f https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/stan-dev/cmdstan.git downstream_hotfix
"""
}
}
}
post {
always {
deleteDir()
}
}
}
stage('Update downstream_tests - develop') {
agent {
docker {
image 'ellerbrock/alpine-bash-git'
label 'linux'
args '--entrypoint='
}
}
when {
beforeAgent true
branch 'develop'
}
steps {
script {
retry(3) {
checkout([
$class: 'GitSCM',
branches: [[name: '*/develop'], [name: '*/downstream_tests']],
userRemoteConfigs: scm.userRemoteConfigs
])
}
withCredentials([usernamePassword(credentialsId: 'a630aebc-6861-4e69-b497-fd7f496ec46b',
usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD')]) {
sh """#!/bin/bash
set -x
git checkout downstream_tests
git reset --hard origin/develop
git status
git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/stan-dev/cmdstan.git downstream_tests
"""
}
}
}
post {
always {
deleteDir()
}
}
}
}
}
}
post {
success {
script {
if (env.BRANCH_NAME == "develop") {
build job: "Stan/CmdStan Performance Tests/master", wait:false
}
utils.mailBuildResults("SUCCESSFUL")
}
}
unstable { script { utils.mailBuildResults("UNSTABLE", "[email protected]") } }
failure { script { utils.mailBuildResults("FAILURE", "[email protected]") } }
}
}