source: Jenkinsfile@ 7e288c4

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 7e288c4 was 7e288c4, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Remove redundant booleans in Jenkinsfile

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