source: Jenkinsfile@ 0c1d240

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr no_list persistent-indexer pthread-emulation qualifiedEnum
Last change on this file since 0c1d240 was 0c1d240, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Tentative to fix parameters on first build of branch

  • Property mode set to 100644
File size: 11.4 KB
Line 
1#!groovy
2
3//===========================================================================================================
4// Main loop of the compilation
5//===========================================================================================================
6node ('master'){
7
8 boolean bIsSandbox = env.BRANCH_NAME == "jenkins-sandbox"
9 def err = null
10 def log_needed = false
11
12 stage_name = ''
13
14 compiler = null
15 arch_name = ''
16 architecture = ''
17
18 do_alltests = false
19 do_benchmark = false
20 do_doc = false
21 do_publish = false
22 do_sendemail = true
23
24 builddir = pwd tmp: true
25 srcdir = pwd tmp: false
26
27 currentBuild.result = "SUCCESS"
28
29 try {
30 //Wrap build to add timestamp to command line
31 wrap([$class: 'TimestamperBuildWrapper']) {
32
33 notify_server(0)
34
35 prepare_build()
36
37 clean()
38
39 checkout()
40
41 notify_server(0)
42
43 build()
44
45 test()
46
47 benchmark()
48
49 build_doc()
50
51 publish()
52
53 notify_server(45)
54 }
55 }
56
57 //If an exception is caught we need to change the status and remember to
58 //attach the build log to the email
59 catch (Exception caughtError) {
60 //rethrow error later
61 err = caughtError
62
63 //An error has occured, the build log is relevent
64 log_needed = true
65
66 //Store the result of the build log
67 currentBuild.result = "${stage_name} FAILURE".trim()
68 }
69
70 finally {
71 //Send email with final results if this is not a full build
72 if( do_sendemail ) {
73 echo 'Notifying users of result'
74 email(currentBuild.result, log_needed, bIsSandbox)
75 }
76
77 echo 'Build Completed'
78
79 /* Must re-throw exception to propagate error */
80 if (err) {
81 throw err
82 }
83 }
84}
85
86//===========================================================================================================
87// Helper classes/variables/routines
88//===========================================================================================================
89//Helper routine to collect information about the git history
90def collect_git_info() {
91
92 checkout scm
93
94 //create the temporary output directory in case it doesn't already exist
95 def out_dir = pwd tmp: true
96 sh "mkdir -p ${out_dir}"
97
98 //parse git logs to find what changed
99 gitRefName = env.BRANCH_NAME
100 sh "git reflog > ${out_dir}/GIT_COMMIT"
101 git_reflog = readFile("${out_dir}/GIT_COMMIT")
102 gitRefOldValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][1]
103 gitRefNewValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][2]
104}
105
106def prepare_build() {
107 properties ([ \
108 [$class: 'ParametersDefinitionProperty', \
109 parameterDefinitions: [ \
110 [$class: 'ChoiceParameterDefinition', \
111 description: 'Which compiler to use', \
112 name: 'Compiler', \
113 choices: 'gcc-6\ngcc-5\ngcc-4.9\nclang', \
114 defaultValue: 'gcc-6', \
115 ], \
116 [$class: 'ChoiceParameterDefinition', \
117 description: 'The target architecture', \
118 name: 'Architecture', \
119 choices: 'x64\nx86', \
120 defaultValue: 'x64', \
121 ], \
122 [$class: 'BooleanParameterDefinition', \
123 description: 'If false, only the quick test suite is ran', \
124 name: 'RunAllTests', \
125 defaultValue: false, \
126 ], \
127 [$class: 'BooleanParameterDefinition', \
128 description: 'If true, jenkins also runs benchmarks', \
129 name: 'RunBenchmark', \
130 defaultValue: false, \
131 ], \
132 [$class: 'BooleanParameterDefinition', \
133 description: 'If true, jenkins also builds documentation', \
134 name: 'BuildDocumentation', \
135 defaultValue: true, \
136 ], \
137 [$class: 'BooleanParameterDefinition', \
138 description: 'If true, jenkins also publishes results', \
139 name: 'Publish', \
140 defaultValue: false, \
141 ], \
142 [$class: 'BooleanParameterDefinition', \
143 description: 'If true, jenkins will not send emails', \
144 name: 'Silent', \
145 defaultValue: false, \
146 ], \
147 ],
148 ]])
149
150 compiler = compiler_from_params( params.Compiler )
151 arch_name = params.Architecture
152 architecture = architecture_from_params( arch_name )
153
154 do_alltests = (params.RunAllTests == 'true')
155 do_benchmark = (params.RunBenchmark == 'true')
156 do_doc = (params.BuildDocumentation == 'true')
157 do_publish = (params.Publish == 'true')
158 do_sendemail = ! (params.Silent == 'true')
159
160 collect_git_info()
161
162 def full = do_alltests ? " (Full)" : ""
163 currentBuild.description = "${compiler.cc_name}:${arch_name}${full}"
164
165 echo """Compiler : ${compiler.cc_name} (${compiler.cpp_cc}/${compiler.cfa_cc})
166Architecture : ${arch_name}
167Arc Flags : ${architecture}
168Run All Tests : ${ pRunAllTests.toString() }
169Run Benchmark : ${ pRunBenchmark.toString() }
170Build Documentation : ${ pBuildDocumentation.toString() }
171Publish : ${ pPublish.toString() }
172Silent : ${ pSilent.toString() }
173"""
174}
175
176def build_stage(String name, Closure block ) {
177 stage_name = name
178 stage(name, block)
179}
180
181def notify_server(int wait) {
182 sh """curl --silent --show-error --data "wait=${wait}" -X POST https://cforall.uwaterloo.ca:8082/jenkins/notify > /dev/null || true"""
183 return
184}
185
186def make_doc() {
187 def err = null
188 try {
189 sh 'make clean > /dev/null'
190 sh 'make > /dev/null 2>&1'
191 }
192 catch (Exception caughtError) {
193 err = caughtError //rethrow error later
194 sh 'cat *.log'
195 }
196 finally {
197 if (err) throw err // Must re-throw exception to propagate error
198 }
199}
200
201//Description of a compiler (Must be serializable since pipelines are persistent)
202class CC_Desc implements Serializable {
203 public String cc_name
204 public String cpp_cc
205 public String cfa_cc
206
207 CC_Desc(String cc_name, String cpp_cc, String cfa_cc) {
208 this.cc_name = cc_name
209 this.cpp_cc = cpp_cc
210 this.cfa_cc = cfa_cc
211 }
212}
213
214def compiler_from_params(cc) {
215 switch( cc ) {
216 case 'gcc-6':
217 return new CC_Desc('gcc-6', 'g++-6', 'gcc-6')
218 break
219 case 'gcc-5':
220 return new CC_Desc('gcc-5', 'g++-5', 'gcc-5')
221 break
222 case 'gcc-4.9':
223 return new CC_Desc('gcc-4.9', 'g++-4.9', 'gcc-4.9')
224 break
225 case 'clang':
226 return new CC_Desc('clang', 'clang++', 'gcc-6')
227 break
228 default :
229 error "Unhandled compiler : ${cc}"
230 }
231}
232
233def architecture_from_params( arch ) {
234 switch( arch ) {
235 case 'x64':
236 return '--host=x86_64'
237 break
238 case 'x86':
239 return '--host=i386'
240 break
241 default :
242 error "Unhandled architecture : ${arch}"
243 }
244}
245
246//===========================================================================================================
247// Main compilation routines
248//===========================================================================================================
249def clean() {
250 build_stage('Cleanup') {
251 // clean the build by wipping the build directory
252 dir(builddir) {
253 deleteDir()
254 }
255
256 //Clean all temporary files to make sure no artifacts of the previous build remain
257 sh 'git clean -fdqx'
258
259 //Reset the git repo so no local changes persist
260 sh 'git reset --hard'
261 }
262}
263
264//Compilation script is done here but environnement set-up and error handling is done in main loop
265def checkout() {
266 build_stage('Checkout') {
267 //checkout the source code and clean the repo
268 checkout scm
269 }
270}
271
272def build() {
273 build_stage('Build') {
274 // Build outside of the src tree to ease cleaning
275 dir (builddir) {
276 //Configure the conpilation (Output is not relevant)
277 //Use the current directory as the installation target so nothing escapes the sandbox
278 //Also specify the compiler by hand
279 targets=""
280 if(do_alltests) {
281 targets="--with-target-hosts='host:debug,host:nodebug'"
282 } else {
283 targets="--with-target-hosts='host:debug'"
284 }
285
286 sh "${srcdir}/configure CXX=${compiler.cpp_cc} ${architecture} ${targets} --with-backend-compiler=${compiler.cfa_cc} --quiet"
287
288 //Compile the project
289 sh 'make -j 8 --no-print-directory'
290 }
291 }
292}
293
294def test() {
295 build_stage('Test') {
296
297 dir (builddir) {
298 //Run the tests from the tests directory
299 if ( do_alltests ) {
300 sh 'make --no-print-directory -C tests all-tests debug=yes'
301 sh 'make --no-print-directory -C tests all-tests debug=no '
302 }
303 else {
304 sh 'make --no-print-directory -C tests'
305 }
306 }
307 }
308}
309
310def benchmark() {
311 build_stage('Benchmark') {
312
313 if( !do_benchmark ) return
314
315 dir (builddir) {
316 //Append bench results
317 sh "make --no-print-directory -C benchmark jenkins githash=${gitRefNewValue} arch=${arch_name} | tee ${srcdir}/bench.json"
318 }
319 }
320}
321
322def build_doc() {
323 build_stage('Documentation') {
324
325 if( !do_doc ) return
326
327 dir ('doc/user') {
328 make_doc()
329 }
330
331 dir ('doc/refrat') {
332 make_doc()
333 }
334 }
335}
336
337def publish() {
338 build_stage('Publish') {
339
340 if( !do_publish ) return
341
342 //Then publish the results
343 sh 'curl --silent --show-error -H \'Content-Type: application/json\' --data @bench.json https://cforall.uwaterloo.ca:8082/jenkins/publish > /dev/null || true'
344 }
345}
346
347//===========================================================================================================
348//Routine responsible of sending the email notification once the build is completed
349//===========================================================================================================
350def gitBranchUpdate(String gitRefOldValue, String gitRefNewValue) {
351 def update = ""
352 sh "git rev-list ${gitRefOldValue}..${gitRefNewValue} > GIT_LOG";
353 readFile('GIT_LOG').eachLine { rev ->
354 sh "git cat-file -t ${rev} > GIT_TYPE"
355 def type = readFile('GIT_TYPE')
356
357 update += " via ${rev} (${type})\n"
358 }
359 def rev = gitRefOldValue
360 sh "git cat-file -t ${rev} > GIT_TYPE"
361 def type = readFile('GIT_TYPE')
362
363 update += " from ${rev} (${type})\n"
364 return update
365
366def output=readFile('result').trim()
367echo "output=$output";
368}
369
370//Standard build email notification
371def email(String status, boolean log, boolean bIsSandbox) {
372 //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
373 //Configurations for email format
374 def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase()
375
376 def gitLog = 'Error retrieving git logs'
377 def gitDiff = 'Error retrieving git diff'
378 def gitUpdate = 'Error retrieving update'
379
380 try {
381 gitUpdate = gitBranchUpdate(gitRefOldValue, gitRefNewValue)
382
383 sh "git rev-list --format=short ${gitRefOldValue}...${gitRefNewValue} > GIT_LOG"
384 gitLog = readFile('GIT_LOG')
385
386 sh "git diff --stat ${gitRefNewValue} ${gitRefOldValue} > GIT_DIFF"
387 gitDiff = readFile('GIT_DIFF')
388 }
389 catch (Exception error) {
390 echo error.toString()
391 echo error.getMessage()
392 }
393
394 def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${status}] - branch ${env.BRANCH_NAME}"
395 def email_body = """This is an automated email from the Jenkins build machine. It was
396generated because of a git hooks/post-receive script following
397a ref change was pushed to the repository containing
398the project "UNNAMED PROJECT".
399
400The branch ${env.BRANCH_NAME} has been updated.
401${gitUpdate}
402
403Check console output at ${env.BUILD_URL} to view the results.
404
405- Status --------------------------------------------------------------
406
407BUILD# ${env.BUILD_NUMBER} - ${status}
408
409- Log -----------------------------------------------------------------
410${gitLog}
411-----------------------------------------------------------------------
412Summary of changes:
413${gitDiff}
414"""
415
416 def email_to = "cforall@lists.uwaterloo.ca"
417
418 if( !bIsSandbox ) {
419 //send email notification
420 emailext body: email_body, subject: email_subject, to: email_to, attachLog: log
421 } else {
422 echo "Would send email to: ${email_to}"
423 echo "With title: ${email_subject}"
424 echo "Content: \n${email_body}"
425 }
426}
Note: See TracBrowser for help on using the repository browser.