source: Jenkinsfile@ 3e93c00

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 3e93c00 was 3e93c00, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

Fix archiving to happen on errors not on success

  • Property mode set to 100644
File size: 14.9 KB
Line 
1#!groovy
2
3import groovy.transform.Field
4
5// For skipping stages
6import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
7
8//===========================================================================================================
9// Main loop of the compilation
10//===========================================================================================================
11
12node('master') {
13 // Globals
14 BuildDir = pwd tmp: true
15 SrcDir = pwd tmp: false
16 Settings = null
17 StageName = ''
18
19 // Local variables
20 def err = null
21 def log_needed = false
22
23 currentBuild.result = "SUCCESS"
24
25 try {
26 //Wrap build to add timestamp to command line
27 wrap([$class: 'TimestamperBuildWrapper']) {
28
29 Settings = prepare_build()
30
31 node(Settings.Architecture.node) {
32 BuildDir = pwd tmp: true
33 SrcDir = pwd tmp: false
34
35 clean()
36
37 checkout()
38
39 build()
40
41 test()
42
43 benchmark()
44
45 build_doc()
46
47 publish()
48 }
49
50 // Update the build directories when exiting the node
51 BuildDir = pwd tmp: true
52 SrcDir = pwd tmp: false
53 }
54 }
55
56 //If an exception is caught we need to change the status and remember to
57 //attach the build log to the email
58 catch (Exception caughtError) {
59 //rethrow error later
60 err = caughtError
61
62 echo err.toString()
63
64 //An error has occured, the build log is relevent
65 log_needed = true
66
67 //Store the result of the build log
68 currentBuild.result = "${StageName} FAILURE".trim()
69 }
70
71 finally {
72 //Send email with final results if this is not a full build
73 email(log_needed)
74
75 echo 'Build Completed'
76
77 /* Must re-throw exception to propagate error */
78 if (err) {
79 throw err
80 }
81 }
82}
83//===========================================================================================================
84// Main compilation routines
85//===========================================================================================================
86def clean() {
87 build_stage('Cleanup', true) {
88 // clean the build by wipping the build directory
89 dir(BuildDir) {
90 deleteDir()
91 }
92 }
93}
94
95//Compilation script is done here but environnement set-up and error handling is done in main loop
96def checkout() {
97 build_stage('Checkout', true) {
98 //checkout the source code and clean the repo
99 final scmVars = checkout scm
100 Settings.GitNewRef = scmVars.GIT_COMMIT
101 Settings.GitOldRef = scmVars.GIT_PREVIOUS_COMMIT
102
103 echo GitLogMessage()
104 }
105}
106
107def build() {
108 debug = true
109 release = Settings.RunAllTests || Settings.RunBenchmark
110 build_stage('Build : configure', true) {
111 // Build outside of the src tree to ease cleaning
112 dir (BuildDir) {
113 //Configure the conpilation (Output is not relevant)
114 //Use the current directory as the installation target so nothing escapes the sandbox
115 //Also specify the compiler by hand
116 targets=""
117 if( Settings.RunAllTests || Settings.RunBenchmark ) {
118 targets="--with-target-hosts='host:debug,host:nodebug'"
119 } else {
120 targets="--with-target-hosts='host:debug'"
121 }
122
123 sh "${SrcDir}/configure CXX=${Settings.Compiler.CXX} CC=${Settings.Compiler.CC} ${Settings.Architecture.flags} ${targets} --quiet"
124
125 // Configure libcfa
126 sh 'make -j 8 --no-print-directory configure-libcfa'
127 }
128 }
129
130 build_stage('Build : cfa-cpp', true) {
131 // Build outside of the src tree to ease cleaning
132 dir (BuildDir) {
133 // Build driver
134 sh 'make -j 8 --no-print-directory -C driver'
135
136 // Build translator
137 sh 'make -j 8 --no-print-directory -C src'
138 }
139 }
140
141 build_stage('Build : libcfa(debug)', debug) {
142 // Build outside of the src tree to ease cleaning
143 dir (BuildDir) {
144 sh "make -j 8 --no-print-directory -C libcfa/${Settings.Architecture.name}-debug"
145 }
146 }
147
148 build_stage('Build : libcfa(nodebug)', release) {
149 // Build outside of the src tree to ease cleaning
150 dir (BuildDir) {
151 sh "make -j 8 --no-print-directory -C libcfa/${Settings.Architecture.name}-nodebug"
152 }
153 }
154}
155
156def test() {
157 build_stage('Test: short', !Settings.RunAllTests) {
158 dir (BuildDir) {
159 //Run the tests from the tests directory
160 sh 'make --no-print-directory -C tests'
161 }
162 }
163
164 build_stage('Test: full', Settings.RunAllTests) {
165 dir (BuildDir) {
166 try {
167 //Run the tests from the tests directory
168 sh """make --no-print-directory -C tests timeouts="--timeout=600 --global-timeout=14400" all-tests debug=yes archiveerrors=${BuildDir}/tests/crashes/debug"""
169 sh """make --no-print-directory -C tests timeouts="--timeout=600 --global-timeout=14400" all-tests debug=no archiveerrors=${BuildDir}/tests/crashes/nodebug"""
170 }
171 catch (Exception err) {
172 echo "Archiving core dumps"
173 archiveArtifacts artifacts: "${BuildDir}/tests/crashes", fingerprint: true
174 throw err
175 }
176 }
177 }
178}
179
180def benchmark() {
181 build_stage('Benchmark', Settings.RunBenchmark) {
182 dir (BuildDir) {
183 //Append bench results
184 sh "make --no-print-directory -C benchmark jenkins arch=${Settings.Architecture.name}"
185 }
186 }
187}
188
189def build_doc() {
190 build_stage('Documentation', Settings.BuildDocumentation) {
191 dir ('doc/user') {
192 make_doc()
193 }
194
195 dir ('doc/refrat') {
196 make_doc()
197 }
198 }
199}
200
201def publish() {
202 build_stage('Publish', true) {
203
204 if( Settings.Publish && !Settings.RunBenchmark ) { echo 'No results to publish!!!' }
205
206 def groupCompile = new PlotGroup('Compilation', 'duration (s) - lower is better', true)
207 def groupConcurrency = new PlotGroup('Concurrency', 'duration (n) - lower is better', false)
208
209 //Then publish the results
210 do_plot(Settings.RunBenchmark && Settings.Publish, 'compile' , groupCompile , false, 'Compilation')
211 do_plot(Settings.RunBenchmark && Settings.Publish, 'compile.diff' , groupCompile , true , 'Compilation (relative)')
212 do_plot(Settings.RunBenchmark && Settings.Publish, 'ctxswitch' , groupConcurrency, false, 'Context Switching')
213 do_plot(Settings.RunBenchmark && Settings.Publish, 'ctxswitch.diff', groupConcurrency, true , 'Context Switching (relative)')
214 do_plot(Settings.RunBenchmark && Settings.Publish, 'mutex' , groupConcurrency, false, 'Mutual Exclusion')
215 do_plot(Settings.RunBenchmark && Settings.Publish, 'mutex.diff' , groupConcurrency, true , 'Mutual Exclusion (relative)')
216 do_plot(Settings.RunBenchmark && Settings.Publish, 'signal' , groupConcurrency, false, 'Internal and External Scheduling')
217 do_plot(Settings.RunBenchmark && Settings.Publish, 'signal.diff' , groupConcurrency, true , 'Internal and External Scheduling (relative)')
218 }
219}
220
221//===========================================================================================================
222//Routine responsible of sending the email notification once the build is completed
223//===========================================================================================================
224def GitLogMessage() {
225 if (!Settings || !Settings.GitOldRef || !Settings.GitNewRef) return "\nERROR retrieveing git information!\n"
226
227 sh "${SrcDir}/tools/PrettyGitLogs.sh ${SrcDir} ${BuildDir} ${Settings.GitOldRef} ${Settings.GitNewRef}"
228
229 def gitUpdate = readFile("${BuildDir}/GIT_UPDATE")
230 def gitLog = readFile("${BuildDir}/GIT_LOG")
231 def gitDiff = readFile("${BuildDir}/GIT_DIFF")
232
233 return """
234<pre>
235The branch ${env.BRANCH_NAME} has been updated.
236${gitUpdate}
237</pre>
238
239<p>Check console output at ${env.BUILD_URL} to view the results.</p>
240
241<p>- Status --------------------------------------------------------------</p>
242
243<p>BUILD# ${env.BUILD_NUMBER} - ${currentBuild.result}</p>
244
245<p>- Log -----------------------------------------------------------------</p>
246
247<pre>
248${gitLog}
249</pre>
250
251<p>-----------------------------------------------------------------------</p>
252<pre>
253Summary of changes:
254${gitDiff}
255</pre>
256"""
257}
258
259//Standard build email notification
260def email(boolean log) {
261 //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
262 //Configurations for email format
263 echo 'Notifying users of result'
264
265 def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase()
266 def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${currentBuild.result}] - branch ${env.BRANCH_NAME}"
267 def email_body = """<p>This is an automated email from the Jenkins build machine. It was
268generated because of a git hooks/post-receive script following
269a ref change which was pushed to the C\u2200 repository.</p>
270""" + GitLogMessage()
271
272 def email_to = !Settings.IsSandbox ? "cforall@lists.uwaterloo.ca" : "tdelisle@uwaterloo.ca"
273
274 if( Settings && !Settings.Silent ) {
275 //send email notification
276 emailext body: email_body, subject: email_subject, to: email_to, attachLog: log
277 } else {
278 echo "Would send email to: ${email_to}"
279 echo "With title: ${email_subject}"
280 echo "Content: \n${email_body}"
281 }
282}
283
284//===========================================================================================================
285// Helper classes/variables/routines
286//===========================================================================================================
287//Description of a compiler (Must be serializable since pipelines are persistent)
288class CC_Desc implements Serializable {
289 public String name
290 public String CXX
291 public String CC
292
293 CC_Desc(String name, String CXX, String CC) {
294 this.name = name
295 this.CXX = CXX
296 this.CC = CC
297 }
298}
299
300//Description of an architecture (Must be serializable since pipelines are persistent)
301class Arch_Desc implements Serializable {
302 public String name
303 public String flags
304 public String node
305
306 Arch_Desc(String name, String flags, String node) {
307 this.name = name
308 this.flags = flags
309 this.node = node
310 }
311}
312
313class BuildSettings implements Serializable {
314 public final CC_Desc Compiler
315 public final Arch_Desc Architecture
316 public final Boolean RunAllTests
317 public final Boolean RunBenchmark
318 public final Boolean BuildDocumentation
319 public final Boolean Publish
320 public final Boolean Silent
321 public final Boolean IsSandbox
322 public final String DescLong
323 public final String DescShort
324
325 public String GitNewRef
326 public String GitOldRef
327
328 BuildSettings(java.util.Collections$UnmodifiableMap param, String branch) {
329 switch( param.Compiler ) {
330 case 'gcc-6':
331 this.Compiler = new CC_Desc('gcc-6', 'g++-6', 'gcc-6')
332 break
333 case 'gcc-5':
334 this.Compiler = new CC_Desc('gcc-5', 'g++-5', 'gcc-5')
335 break
336 case 'gcc-4.9':
337 this.Compiler = new CC_Desc('gcc-4.9', 'g++-4.9', 'gcc-4.9')
338 break
339 case 'clang':
340 this.Compiler = new CC_Desc('clang', 'clang++', 'gcc-6')
341 break
342 default :
343 error "Unhandled compiler : ${cc}"
344 }
345
346 switch( param.Architecture ) {
347 case 'x64':
348 this.Architecture = new Arch_Desc('x64', '--host=x86_64', 'x64')
349 break
350 case 'x86':
351 this.Architecture = new Arch_Desc('x86', '--host=i386', 'x86')
352 break
353 default :
354 error "Unhandled architecture : ${arch}"
355 }
356
357 this.IsSandbox = (branch == "jenkins-sandbox")
358 this.RunAllTests = param.RunAllTests
359 this.RunBenchmark = param.RunBenchmark
360 this.BuildDocumentation = param.BuildDocumentation
361 this.Publish = param.Publish
362 this.Silent = param.Silent
363
364 def full = param.RunAllTests ? " (Full)" : ""
365 this.DescShort = "${ this.Compiler.name }:${ this.Architecture.name }${full}"
366
367 this.DescLong = """Compiler : ${ this.Compiler.name } (${ this.Compiler.CXX }/${ this.Compiler.CC })
368Architecture : ${ this.Architecture.name }
369Arc Flags : ${ this.Architecture.flags }
370Run All Tests : ${ this.RunAllTests.toString() }
371Run Benchmark : ${ this.RunBenchmark.toString() }
372Build Documentation : ${ this.BuildDocumentation.toString() }
373Publish : ${ this.Publish.toString() }
374Silent : ${ this.Silent.toString() }
375"""
376
377 this.GitNewRef = ''
378 this.GitOldRef = ''
379 }
380}
381
382class PlotGroup implements Serializable {
383 public String name
384 public String unit
385 public boolean log
386
387 PlotGroup(String name, String unit, boolean log) {
388 this.name = name
389 this.unit = unit
390 this.log = log
391 }
392}
393
394def prepare_build() {
395 // prepare the properties
396 properties ([ \
397 [$class: 'ParametersDefinitionProperty', \
398 parameterDefinitions: [ \
399 [$class: 'ChoiceParameterDefinition', \
400 description: 'Which compiler to use', \
401 name: 'Compiler', \
402 choices: 'gcc-6\ngcc-5\ngcc-4.9\nclang', \
403 defaultValue: 'gcc-6', \
404 ], \
405 [$class: 'ChoiceParameterDefinition', \
406 description: 'The target architecture', \
407 name: 'Architecture', \
408 choices: 'x64\nx86', \
409 defaultValue: 'x64', \
410 ], \
411 [$class: 'BooleanParameterDefinition', \
412 description: 'If false, only the quick test suite is ran', \
413 name: 'RunAllTests', \
414 defaultValue: false, \
415 ], \
416 [$class: 'BooleanParameterDefinition', \
417 description: 'If true, jenkins also runs benchmarks', \
418 name: 'RunBenchmark', \
419 defaultValue: false, \
420 ], \
421 [$class: 'BooleanParameterDefinition', \
422 description: 'If true, jenkins also builds documentation', \
423 name: 'BuildDocumentation', \
424 defaultValue: true, \
425 ], \
426 [$class: 'BooleanParameterDefinition', \
427 description: 'If true, jenkins also publishes results', \
428 name: 'Publish', \
429 defaultValue: false, \
430 ], \
431 [$class: 'BooleanParameterDefinition', \
432 description: 'If true, jenkins will not send emails', \
433 name: 'Silent', \
434 defaultValue: false, \
435 ], \
436 ],
437 ]])
438
439 // It's unfortunate but it looks like we need to checkout the entire repo just to get the pretty git printer
440 checkout scm
441
442 final settings = new BuildSettings(params, env.BRANCH_NAME)
443
444 currentBuild.description = settings.DescShort
445 echo settings.DescLong
446
447 return settings
448}
449
450def build_stage(String name, boolean run, Closure block ) {
451 StageName = name
452 echo " -------- ${StageName} -------- "
453 if(run) {
454 stage(name, block)
455 } else {
456 stage(name) { Utils.markStageSkippedForConditional(STAGE_NAME) }
457 }
458}
459
460def make_doc() {
461 def err = null
462 try {
463 sh 'make clean > /dev/null'
464 sh 'make > /dev/null 2>&1'
465 }
466 catch (Exception caughtError) {
467 err = caughtError //rethrow error later
468 sh 'cat build/*.log'
469 }
470 finally {
471 if (err) throw err // Must re-throw exception to propagate error
472 }
473}
474
475def do_plot(boolean new_data, String file, PlotGroup group, boolean relative, String title) {
476
477 if(new_data) {
478 echo "Publishing new data"
479 }
480
481 def series = new_data ? [[
482 file: "${file}.csv",
483 exclusionValues: '',
484 displayTableFlag: false,
485 inclusionFlag: 'OFF',
486 url: ''
487 ]] : [];
488
489 echo "file is ${BuildDir}/benchmark/${file}.csv, group ${group}, title ${title}"
490 dir("${BuildDir}/benchmark/") {
491 plot csvFileName: "cforall-${env.BRANCH_NAME}-${file}.csv",
492 csvSeries: series,
493 group: "${group.name}",
494 title: "${title}",
495 style: 'lineSimple',
496 exclZero: false,
497 keepRecords: false,
498 logarithmic: !relative && group.log,
499 numBuilds: '120',
500 useDescr: true,
501 yaxis: group.unit,
502 yaxisMaximum: '',
503 yaxisMinimum: ''
504 }
505}
Note: See TracBrowser for help on using the repository browser.