source: Jenkinsfile@ fd6d74e

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 new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new stuck-waitfor-destruct with_gc
Last change on this file since fd6d74e was fd6d74e, checked in by Thierry Delisle <tdelisle@…>, 9 years ago

Forgot to implement silent option

  • Property mode set to 100644
File size: 9.9 KB
RevLine 
[a63ad80]1#!groovy
2
[29f4fe62]3//===========================================================================================================
[9beae23]4// Main loop of the compilation
[29f4fe62]5//===========================================================================================================
[9beae23]6node ('master'){
[56a9ce6]7
[9beae23]8 boolean bIsSandbox = env.BRANCH_NAME == "jenkins-sandbox"
9 def err = null
10 def log_needed = false
[0ef06b6]11
[bd34bcf5]12 compiler = null
13 architecture = ''
[95fdb0a]14
[bd34bcf5]15 do_alltests = false
16 do_benchmark = false
17 do_doc = false
18 do_publish = false
[56a9ce6]19
[0ef06b6]20 currentBuild.result = "SUCCESS"
21
[9beae23]22 try {
[95fdb0a]23 //Wrap build to add timestamp to command line
24 wrap([$class: 'TimestamperBuildWrapper']) {
[23a14d86]25
[95fdb0a]26 //Prevent the build from exceeding 60 minutes
27 timeout(60) {
28
[7223c671]29 notify_server()
[7aebc62]30
[0ef06b6]31 prepare_build()
[fde808df]32
[95fdb0a]33 checkout()
34
35 build()
36
37 test()
38
39 benchmark()
[7359098]40
[95fdb0a]41 clean()
[7359098]42
[95fdb0a]43 build_doc()
[9beae23]44
[95fdb0a]45 publish()
46
[7223c671]47 notify_server()
[9beae23]48 }
49 }
[738cf8f]50 }
51
[9beae23]52 //If an exception is caught we need to change the status and remember to
53 //attach the build log to the email
[738cf8f]54 catch (Exception caughtError) {
55 //rethrow error later
56 err = caughtError
57
[9beae23]58 //An error has occured, the build log is relevent
59 log_needed = true
60
61 //Store the result of the build log
62 currentBuild.result = "${status_prefix} FAILURE".trim()
[738cf8f]63 }
64
65 finally {
[9beae23]66 echo 'Build Completed'
67
68 //Send email with final results if this is not a full build
[95fdb0a]69 if( !do_sendemail && !bIsSandbox ) {
[9beae23]70 echo 'Notifying users of result'
71 email(currentBuild.result, log_needed)
72 }
73
[738cf8f]74 /* Must re-throw exception to propagate error */
75 if (err) {
76 throw err
77 }
78 }
79}
80
[29f4fe62]81//===========================================================================================================
[95fdb0a]82// Helper classes/variables/routines
[29f4fe62]83//===========================================================================================================
[ab60d6d]84//Helper routine to collect information about the git history
85def collect_git_info() {
86
[abc26975]87 //create the temporary output directory in case it doesn't already exist
[ab60d6d]88 def out_dir = pwd tmp: true
[abc26975]89 sh "mkdir -p ${out_dir}"
90
91 //parse git logs to find what changed
[ab60d6d]92 gitRefName = env.BRANCH_NAME
93 dir("../${gitRefName}@script") {
94 sh "git reflog > ${out_dir}/GIT_COMMIT"
95 }
96 git_reflog = readFile("${out_dir}/GIT_COMMIT")
97 gitRefOldValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][1]
98 gitRefNewValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][2]
99}
100
[0ef06b6]101def prepare_build() {
[95fdb0a]102 properties ([ \
103 [$class: 'ParametersDefinitionProperty', \
104 parameterDefinitions: [ \
105 [$class: 'ChoiceParameterDefinition', \
106 description: 'Which compiler to use', \
[fd6d74e]107 name: 'Compiler', \
[95fdb0a]108 choices: 'gcc-6\ngcc-5\ngcc-4.9\nclang', \
109 defaultValue: 'gcc-6', \
110 ], \
111 [$class: 'ChoiceParameterDefinition', \
112 description: 'The target architecture', \
[fd6d74e]113 name: 'Architecture', \
[95fdb0a]114 choices: '64-bit\n32-bit', \
115 defaultValue: '64-bit', \
116 ], \
117 [$class: 'BooleanParameterDefinition', \
118 description: 'If false, only the quick test suite is ran', \
[fd6d74e]119 name: 'RunAllTests', \
[95fdb0a]120 defaultValue: false, \
121 ], \
122 [$class: 'BooleanParameterDefinition', \
123 description: 'If true, jenkins also runs benchmarks', \
[fd6d74e]124 name: 'RunBenchmark', \
[95fdb0a]125 defaultValue: false, \
126 ], \
127 [$class: 'BooleanParameterDefinition', \
128 description: 'If true, jenkins also builds documentation', \
[fd6d74e]129 name: 'BuildDocumentation', \
[95fdb0a]130 defaultValue: false, \
131 ], \
132 [$class: 'BooleanParameterDefinition', \
133 description: 'If true, jenkins also publishes results', \
[fd6d74e]134 name: 'paramPublish_publish', \
135 defaultValue: false, \
136 ], \
137 [$class: 'BooleanParameterDefinition', \
138 description: 'If true, jenkins will not send emails', \
139 name: 'Silent', \
[95fdb0a]140 defaultValue: false, \
141 ], \
142 ],
[0ef06b6]143 ]])
144
[fd6d74e]145 compiler = compiler_from_params( Compiler )
146 architecture = architecture_from_params( Architecture )
[0ef06b6]147
[fd6d74e]148 do_alltests = RunAllTests.toBoolean()
149 do_benchmark = RunBenchmark.toBoolean()
150 do_doc = BuildDocumentation.toBoolean()
151 do_publish = Publish.toBoolean()
152 do_sendemail = ! Silent.toBoolean()
[0ef06b6]153
[6802a5f]154 echo """Compiler : ${compiler.name} (${compiler.cpp_cc}/${compiler.cfa_cc})
155Architecture : ${architecture}
156Run All Tests : ${ param_allTests.toString() }
157Run Benchmark : ${ param_benchmark.toString() }
158Build Documentation : ${ param_doc.toString() }
159Publish : ${ param_publish.toString() }
[fd6d74e]160Silent : ${ do_sendemail.toString() }
[6802a5f]161"""
162
[0ef06b6]163 collect_git_info()
[95fdb0a]164}
[0ef06b6]165
[7223c671]166def notify_server() {
[95fdb0a]167 sh 'curl --data "" http://plg2:8082/jenkins/notify'
[ed50f0ba]168 return
[95fdb0a]169}
170
171def make_doc() {
172 def err = null
173 try {
174 sh 'make clean > /dev/null'
175 sh 'make > /dev/null 2>&1'
176 }
177 catch (Exception caughtError) {
178 err = caughtError //rethrow error later
179 sh 'cat *.log'
180 }
181 finally {
182 if (err) throw err // Must re-throw exception to propagate error
[bd34bcf5]183 }
184}
185
186//Description of a compiler (Must be serializable since pipelines are persistent)
187class CC_Desc implements Serializable {
188 public String cc_name
189 public String cpp_cc
[6802a5f]190 public String cfa_cc
[bd34bcf5]191
[6802a5f]192 CC_Desc(String cc_name, String cpp_cc, String cfa_cc) {
[bd34bcf5]193 this.cc_name = cc_name
194 this.cpp_cc = cpp_cc
[6802a5f]195 this.cfa_cc = cfa_cc
[bd34bcf5]196 }
197}
198
199def compiler_from_params(cc) {
200 switch( cc ) {
201 case 'gcc-6':
202 return new CC_Desc('gcc-6', 'g++-6', 'gcc-6')
203 break
204 case 'gcc-5':
205 return new CC_Desc('gcc-5', 'g++-5', 'gcc-5')
206 break
207 case 'gcc-4.9':
208 return new CC_Desc('gcc-4.9', 'g++-4.9', 'gcc-4.9')
209 break
210 case 'clang':
[6802a5f]211 return new CC_Desc('clang', 'clang++', 'gcc-6')
[bd34bcf5]212 break
[1e6a463]213 default :
[bd34bcf5]214 error 'Unhandled compiler'
215 }
216}
217
218def architecture_from_params( arch ) {
219 switch( arch ) {
220 case '64-bit':
221 return '--host=x86_64 CXXFLAGS="-m64" CFAFLAGS="-m64"'
222 break
223 case '32-bit':
224 return '--host=i386 CXXFLAGS="-m32" CFAFLAGS="-m32"'
225 break
[1e6a463]226 default :
[bd34bcf5]227 error 'Unhandled architecture'
[95fdb0a]228 }
[0ef06b6]229}
230
[29f4fe62]231//===========================================================================================================
[9beae23]232// Main compilation routines
[29f4fe62]233//===========================================================================================================
[9beae23]234//Compilation script is done here but environnement set-up and error handling is done in main loop
[95fdb0a]235def checkout() {
236 stage 'Checkout'
[9beae23]237 //checkout the source code and clean the repo
238 checkout scm
[77f347d]239
[9beae23]240 //Clean all temporary files to make sure no artifacts of the previous build remain
241 sh 'git clean -fdqx'
[40b1df9]242
[9beae23]243 //Reset the git repo so no local changes persist
244 sh 'git reset --hard'
[95fdb0a]245}
[29f4fe62]246
[95fdb0a]247def build() {
248 stage 'Build'
249
250 def install_dir = pwd tmp: true
251
[9beae23]252 //Configure the conpilation (Output is not relevant)
253 //Use the current directory as the installation target so nothing
254 //escapes the sandbox
255 //Also specify the compiler by hand
[6802a5f]256 sh "./configure CXX=${compiler.cpp_cc} ${architecture} --with-backend-compiler=${compiler.cfa_cc} --prefix=${install_dir} --enable-silent-rules --quiet"
[9e5f409]257
[9beae23]258 //Compile the project
259 sh 'make -j 8 --no-print-directory V=0 install'
[95fdb0a]260}
[24eecab]261
[95fdb0a]262def test() {
263 stage 'Test'
[9e5f409]264
[9beae23]265 //Run the tests from the tests directory
[95fdb0a]266 if ( do_alltests ) {
[9beae23]267 sh 'make -C src/tests all-tests debug=yes'
268 sh 'make -C src/tests all-tests debug=no'
269 }
270 else {
271 sh 'make -C src/tests'
272 }
[95fdb0a]273}
274
275def benchmark() {
276 stage 'Benchmark'
[29f4fe62]277
[95fdb0a]278 if( !do_bencmark ) return
[ae28ee2]279
280 //Write the commit id to Benchmark
[f9fa306]281 writeFile file: 'bench.csv', text:'data=' + gitRefNewValue + ','
[ae28ee2]282
283 //Append bench results
[f9fa306]284 sh 'make -C src/benchmark --no-print-directory csv-data >> bench.csv'
[95fdb0a]285}
[ae28ee2]286
[95fdb0a]287def clean() {
288 stage 'Cleanup'
[d56c05d0]289
[9beae23]290 //do a maintainer-clean to make sure we need to remake from scratch
291 sh 'make maintainer-clean > /dev/null'
292}
[efd60d67]293
[95fdb0a]294def build_doc() {
[9beae23]295 stage 'Documentation'
296
[95fdb0a]297 if( !do_doc ) return
[9beae23]298
299 dir ('doc/user') {
300 make_doc()
301 }
302
303 dir ('doc/refrat') {
304 make_doc()
305 }
306}
307
[95fdb0a]308def publish() {
309 stage 'Publish'
310
311 if( !do_publish ) return
312
313 //Then publish the results
314 sh 'curl --data @bench.csv http://plg2:8082/jenkins/publish'
315}
316
[29f4fe62]317//===========================================================================================================
318//Routine responsible of sending the email notification once the build is completed
319//===========================================================================================================
[a235d09]320//Standard build email notification
[19ad15b]321def email(String status, boolean log) {
[e8a22a7]322 //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
323 //Configurations for email format
324 def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase()
325
[0a346e5]326 def gitLog = 'Error retrieving git logs'
327 def gitDiff = 'Error retrieving git diff'
[7b1a604]328
[0a346e5]329 try {
330
331 sh "git rev-list --format=short ${gitRefOldValue}...${gitRefNewValue} > GIT_LOG"
332 gitLog = readFile('GIT_LOG')
333
334 sh "git diff --stat ${gitRefNewValue} ${gitRefOldValue} > GIT_DIFF"
335 gitDiff = readFile('GIT_DIFF')
336 }
337 catch (Exception error) {}
[7b1a604]338
[992c26d]339 def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${status}] - branch ${env.BRANCH_NAME}"
[848fb00]340 def email_body = """This is an automated email from the Jenkins build machine. It was
341generated because of a git hooks/post-receive script following
342a ref change was pushed to the repository containing
343the project "UNNAMED PROJECT".
[e8a22a7]344
[848fb00]345The branch ${env.BRANCH_NAME} has been updated.
[a235d09]346 via ${gitRefOldValue} (commit)
347 from ${gitRefNewValue} (commit)
[7b1a604]348
349Check console output at ${env.BUILD_URL} to view the results.
350
351- Status --------------------------------------------------------------
352
353BUILD# ${env.BUILD_NUMBER} - ${status}
[e8a22a7]354
[7b1a604]355- Log -----------------------------------------------------------------
356${gitLog}
357-----------------------------------------------------------------------
358Summary of changes:
359${gitDiff}
360"""
[e8a22a7]361
[a6b7480]362 def email_to = "pabuhr@uwaterloo.ca, rschlunt@uwaterloo.ca, a3moss@uwaterloo.ca, tdelisle@uwaterloo.ca, brice.dobry@huawei.com"
[e8a22a7]363
364 //send email notification
[1e34653]365 emailext body: email_body, subject: email_subject, to: email_to, attachLog: log
[e8a22a7]366}
Note: See TracBrowser for help on using the repository browser.