-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathJenkinsfile
More file actions
369 lines (314 loc) · 12.8 KB
/
Jenkinsfile
File metadata and controls
369 lines (314 loc) · 12.8 KB
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
def OSList = [
['Ubuntu 18.04 (amd64)', 'ubuntu-18-amd64', 'docker && linux-amd64'],
['Ubuntu 20.04 (amd64)', 'ubuntu-20-amd64', 'docker && linux-amd64'],
['Ubuntu 22.04 (amd64)', 'ubuntu-22-amd64', 'docker && linux-amd64'],
['Ubuntu 24.04 (amd64)', 'ubuntu-24-amd64', 'docker && linux-amd64'],
['Ubuntu 24.04 (arm64)', 'ubuntu-24-arm64', 'docker && linux-aarch64'],
['RHEL 7 (x86_64)', 'rhel-7-x86_64', 'docker && linux-amd64'],
['RHEL 8 (x86_64)', 'rhel-8-x86_64', 'docker && linux-amd64'],
['RHEL 9 (x86_64)', 'rhel-9-x86_64', 'docker && linux-amd64'],
['Debian 10 (amd64)', 'debian-10-amd64', 'docker && linux-amd64'],
['Debian 11 (amd64)', 'debian-11-amd64', 'docker && linux-amd64'],
['Debian 12 (amd64)', 'debian-12-amd64', 'docker && linux-amd64'],
['Debian 12 (arm64)', 'debian-12-arm64', 'docker && linux-aarch64'],
['Windows (x86)', 'windows-x86', 'docker && linux-amd64'],
['Windows (x64)', 'windows-x64', 'docker && linux-amd64'],
['MacOSX (homebrew)', 'macosx-homebrew', 'macosx'],
['MacOSX (macports)', 'macosx-macports', 'macosx'],
// Disabled until https://github.com/MDSplus/mdsplus/issues/2605 is fixed
// ['Address Sanitizer', 'test-asan', 'docker && linux-amd64'],
['Thread Sanitizer', 'test-tsan', 'docker && linux-amd64'],
['Undefined Behavior Sanitizer', 'test-ubsan', 'docker && linux-amd64'],
['Helgrind', 'test-helgrind', 'docker && linux-amd64'],
['Memcheck', 'test-memcheck', 'docker && linux-amd64'],
]
def getNumThreads() {
if (env.THREADS) {
return env.THREADS;
}
return "8";
}
def setupStage() {
return {
stage("Setup") {
echo "Building on ${NODE_NAME}"
// Useful for debugging
sh 'printenv'
// This shouldn't be needed, but just in case
cleanWs disableDeferredWipeout: true, deleteDirs: true
unstash 'source'
// HACK: This should be done before stashing the source, but it causes issues with create_github_release
// so instead each distribution tags separately
def new_tag = readFile(file: "new_tag")
sh "git tag ${new_tag} || true"
}
}
}
def testStage(os) {
def extraArgs = ""
if (os.startsWith("macosx-")) { // || OS.startsWith("windows-")
// Required to isolate runs on systems that don't have docker networks to do the isolation
def offset = (EXECUTOR_NUMBER as int) * 1000
extraArgs += "-DTEST_PORT_OFFSET=${offset}"
}
else {
extraArgs += " --dockerpull --dockernetwork=jenkins-${EXECUTOR_NUMBER}"
}
return {
stage("Build & Test (Debug)") {
try {
def threads = getNumThreads()
sh "deploy/build.py -j${threads} --os=${os} -DCMAKE_BUILD_TYPE=Debug --build --test --output-junit ${extraArgs}"
}
finally {
junit skipPublishingChecks: true, testResults: "workspace-${os}/mdsplus-junit.xml", keepLongStdio: true
}
}
stage("Build & Test (Release)") {
try {
def threads = getNumThreads()
sh "deploy/build.py -j${threads} --os=${os} -DCMAKE_BUILD_TYPE=RelWithDebInfo --build --test --output-junit --junit-suite-name '${os}-release' ${extraArgs}"
}
finally {
junit skipPublishingChecks: true, testResults: "workspace-${os}/mdsplus-junit.xml", keepLongStdio: true
}
}
}
}
def packageStage(os) {
return {
stage("Build & Package") {
def threads = getNumThreads()
sh "deploy/build.py -j${threads} --os=${os} -DCMAKE_BUILD_TYPE=Release --build --package --verify-packages"
dir("workspace-${os}") {
stash name: "packages-${os}", includes: "packages/**/*"
stash name: "dist-${os}", includes: "mdsplus-publish.json,dist/**/*"
archiveArtifacts artifacts: "packages/*.tgz,packages/*.exe", followSymlinks: false
}
}
}
}
def cleanStage() {
return {
stage("Clean") {
// Collect valgrind core dumps
archiveArtifacts artifacts: "**/core", followSymlinks: false, allowEmptyArchive: true
cleanWs disableDeferredWipeout: true, deleteDirs: true
}
}
}
def distributions = OSList.collectEntries {
info -> [ "${info[0]}": {
def (name, os, label) = info
node (label) {
stage(name) {
ansiColor('xterm') {
try {
setupStage().call()
testStage(os).call()
if (!os.startsWith("test-")) {
packageStage(os).call()
}
}
finally {
cleanStage().call()
}
}
}
}
}]
}
def localTest(name, label, testStages) {
return {
stage(name) {
node(label) {
ansiColor('xterm') {
try {
setupStage().call()
stage("Build") {
def threads = getNumThreads()
sh "deploy/build.py -j${threads} --build --install -DCMAKE_BUILD_TYPE=Debug"
}
testStages.call()
}
finally {
cleanStage().call()
}
}
}
}
}
}
distributions['IDL'] = localTest('IDL', 'linux-amd64', {
stage("Test") {
try {
withEnv(["MDSPLUS_DIR=${WORKSPACE}/workspace/install/usr/local/mdsplus"]) {
sh """
set +x
. \$MDSPLUS_DIR/setup.sh
export PYTHONPATH=\$MDSPLUS_DIR/python/
set -x
./idl/testing/run_tests.py
"""
}
}
finally {
// junit skipPublishingChecks: true, testResults: "mdsplus-junit.xml", keepLongStdio: true
}
}
})
distributions['MATLAB'] = localTest('MATLAB', 'linux-amd64', {
stage("Test") {
withEnv(["MDSPLUS_DIR=${WORKSPACE}/workspace/install/usr/local/mdsplus"]) {
sh """
set +x
. \$MDSPLUS_DIR/setup.sh
export PYTHONPATH=\$MDSPLUS_DIR/python/
set -x
echo "Testing MATLAB"
"""
}
}
})
def AdminList = [
'dgarnier',
'GabrieleManduchi',
'heidthecamp',
'joshStillerman',
'mwinkel-dev',
'santorofer',
'WhoBrokeTheBuild',
'zack-vii',
]
def schedule = "";
if (BRANCH_NAME == "alpha") {
schedule = "0 18 * * *";
}
if (BRANCH_NAME == "stable") {
schedule = "0 19 * * *";
}
def new_version = null;
def new_tag = null;
pipeline {
agent {
label 'built-in'
}
options {
skipDefaultCheckout()
timeout(time: 1, unit: 'HOURS')
buildDiscarder(logRotator(daysToKeepStr: '90', artifactNumToKeepStr: '90'))
}
triggers {
cron(schedule)
issueCommentTrigger('(?i).*retest\\s+this\\s+please.*')
}
stages {
stage('Setup') {
steps {
sh 'printenv'
script {
// is PR
if (env.CHANGE_ID) {
// This is safe because untrusted PRs will use Jenkinsfile from the target branch
if (env.GITHUB_COMMENT_AUTHOR) {
if (!AdminList.contains(env.GITHUB_COMMENT_AUTHOR)) {
currentBuild.result = 'ABORTED'
error 'This user does not have permission to trigger builds.'
}
else {
echo("Build was started by ${GITHUB_COMMENT_AUTHOR}, who wrote: \"${GITHUB_COMMENT}\", which matches the trigger pattern.")
}
}
else if (!AdminList.contains(env.CHANGE_AUTHOR)) {
currentBuild.result = 'ABORTED'
error 'This user does not have permission to trigger builds.'
}
}
}
// This shouldn't be needed, but just in case
cleanWs disableDeferredWipeout: true, deleteDirs: true
retry(3) {
checkout scm;
}
script {
new_version = sh(
script: "/usr/bin/python3 deploy/get_new_version.py",
returnStdout: true
).trim()
if (new_version != '0.0.0') {
new_tag = "${BRANCH_NAME}_release-" + new_version.replaceAll("\\.", "-")
echo "Calculated new version to be ${new_version}"
// NOTE: To avoid confusing create_github_release, we cannot create the tag now
// so instead we write it to a file, and tag it during the setup stage of each distribution
writeFile(file: "new_tag", text: new_tag)
}
}
// By default it excludes .git/
stash name: 'source', includes: '**', useDefaultExcludes: false
}
}
stage('Distributions') {
steps {
script {
parallel distributions
}
}
}
stage('Publish') {
when {
allOf {
anyOf {
branch 'alpha';
branch 'stable';
}
triggeredBy 'TimerTrigger'
}
}
steps {
script {
ansiColor('xterm') {
for (info in OSList) {
def (name, os, label) = info
if (os.startsWith("test-")) {
continue;
}
unstash "packages-${os}"
unstash "dist-${os}"
sh "deploy/publish.py --dist-dir=/mnt/mdsplus_staging/dist --cert-dir=/mnt/mdsplus_staging/certs --publish-info=mdsplus-publish.json"
}
// Create a package containing only the MATLAB code, primarily for use with the mdsthin bridge
tar(file: "packages/mdsplus_${BRANCH_NAME}_${new_version}_matlab.tgz", archive: true, compress: true, dir: "matlab/")
def release_file_list = [];
dir("packages") {
sh "ls"
def prefix = pwd()
findFiles(glob: "*.tgz,*.exe").each {
file -> release_file_list.add("${prefix}/${file.path}")
}
}
echo "Creating GitHub Release and Tag for ${new_tag}"
withCredentials([
usernamePassword(
credentialsId: 'MDSplusJenkins',
usernameVariable: 'GITHUB_APP',
passwordVariable: 'GITHUB_ACCESS_TOKEN'
)]) {
// TODO: Protect against spaces in filenames
def release_file_list_arg = release_file_list.join(" ")
sh "./deploy/create_github_release.py --tag ${new_tag} --api-token \$GITHUB_ACCESS_TOKEN ${release_file_list_arg}"
}
cleanWs disableDeferredWipeout: true, deleteDirs: true
}
}
}
}
}
post {
failure {
// if alpha/stable
mail subject: 'Build is failing',
body: "Build is failing: ${BUILD_URL}",
to: 'mdsplus-jenkins-alerts@lists.psfc.mit.edu'
}
}
}