-
-
Notifications
You must be signed in to change notification settings - Fork 373
/
Copy pathJenkinsfile
255 lines (244 loc) · 9.67 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
@Library('StanUtils')
import org.stan.Utils
def utils = new org.stan.Utils()
def setupCXX(failOnError = true) {
errorStr = failOnError ? "-Werror " : ""
writeFile(file: "make/local", text: "CXX=${env.CXX} ${errorStr}")
}
def runTests(String testPath, Boolean separateMakeStep=true) {
if (separateMakeStep) {
sh "./runTests.py -j${env.PARALLEL} ${testPath} --make-only"
}
try { sh "./runTests.py -j${env.PARALLEL} ${testPath}" }
finally { junit 'test/**/*.xml' }
}
def runTestsWin(String testPath) {
withEnv(['PATH+TBB=./lib/stan_math/lib/tbb']) {
bat "runTests.py -j${env.PARALLEL} ${testPath} --make-only"
try { bat "runTests.py -j${env.PARALLEL} ${testPath}" }
finally { junit 'test/**/*.xml' }
}
}
def deleteDirWin() {
bat "attrib -r -s /s /d"
deleteDir()
}
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
}
}
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')
}
options {
skipDefaultCheckout()
preserveStashes(buildCount: 7)
}
stages {
stage('Kill previous builds') {
when {
not { branch 'develop' }
not { branch 'master' }
not { branch 'downstream_tests' }
}
steps {
script {
utils.killOldBuilds()
}
}
}
stage('Linting & Doc checks') {
agent any
steps {
script {
sh "printenv"
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()
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")
],
blameDisabled: false,
qualityGates: [[threshold: 1, type: 'TOTAL', unstable: true]],
healthy: 10, unhealthy: 100, minimumSeverity: 'HIGH',
referenceJobName: env.BRANCH_NAME
deleteDir()
}
}
}
stage("Clang-format") {
agent any
steps {
sh "printenv"
deleteDir()
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 config --global user.email "[email protected]"
git config --global 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('Unit tests') {
parallel {
stage('Windows Headers & Unit') {
agent { label 'windows' }
steps {
deleteDirWin()
unstash 'StanSetup'
setupCXX()
bat "mingw32-make -j${env.PARALLEL} test-headers"
setupCXX(false)
runTestsWin("src/test/unit")
}
post { always { deleteDirWin() } }
}
stage('Unit') {
agent any
steps {
unstash 'StanSetup'
setupCXX(false)
runTests("src/test/unit")
}
post { always { deleteDir() } }
}
}
}
stage('Integration') {
agent any
steps {
unstash 'StanSetup'
setupCXX()
runTests("src/test/integration", separateMakeStep=false)
}
post { always { deleteDir() } }
}
stage('Upstream CmdStan tests') {
when { expression { env.BRANCH_NAME ==~ /PR-\d+/ ||
env.BRANCH_NAME == "downstream_tests" ||
env.BRANCH_NAME == "downstream_hotfix" } }
steps {
build(job: "CmdStan/${cmdstan_pr()}",
parameters: [string(name: 'stan_pr', value: stan_pr()),
string(name: 'math_pr', value: params.math_pr)])
}
}
stage('Performance') {
agent { label 'oldimac' }
steps {
unstash 'StanSetup'
setupCXX()
sh """
./runTests.py -j${env.PARALLEL} src/test/performance
cd test/performance
RScript ../../src/test/performance/plot_performance.R
"""
}
post {
always {
retry(2) {
junit 'test/**/*.xml'
archiveArtifacts 'test/performance/performance.csv,test/performance/performance.png'
perfReport compareBuildPrevious: true, errorFailedThreshold: 0, errorUnstableThreshold: 0, failBuildIfNoResultFile: false, modePerformancePerTestCase: true, sourceDataFiles: 'test/performance/**.xml'
}
deleteDir()
}
}
}
}
post {
always {
node("osx || linux") {
recordIssues id: "pipeline",
name: "Entire pipeline results",
enabledForFailure: true,
aggregatingResults : false,
tools: [
gcc4(id: "pipeline_gcc4", name: "GNU C Compiler"),
clang(id: "pipeline_clang", name: "LLVM/Clang")
],
blameDisabled: false,
qualityGates: [[threshold: 30, type: 'TOTAL', unstable: true]],
healthy: 10, unhealthy: 100, minimumSeverity: 'HIGH',
referenceJobName: env.BRANCH_NAME
}
}
success {
script {
utils.updateUpstream(env,'cmdstan')
utils.mailBuildResults("SUCCESSFUL")
}
}
unstable { script { utils.mailBuildResults("UNSTABLE", "[email protected]") } }
failure { script { utils.mailBuildResults("FAILURE", "[email protected]") } }
}
}