source: Jenkinsfile@ 38eef0e

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 with_gc
Last change on this file since 38eef0e was 38eef0e, checked in by Thierry Delisle <tdelisle@…>, 9 years ago

Wrong variable names

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