[c9d651d] | 1 | |
---|
| 2 | |
---|
[fde808df] | 3 | node ('master'){ |
---|
[23a14d86] | 4 | |
---|
[fde808df] | 5 | def err = null |
---|
| 6 | def stage_name |
---|
| 7 | def log_needed = false |
---|
| 8 | currentBuild.result = "SUCCESS" |
---|
[7aebc62] | 9 | |
---|
[d3d0069] | 10 | try { |
---|
[fde808df] | 11 | |
---|
| 12 | stage 'Checkout' |
---|
| 13 | |
---|
| 14 | //checkout the source code and clean the repo |
---|
| 15 | checkout scm |
---|
| 16 | sh 'git clean -dfq' |
---|
| 17 | |
---|
| 18 | stage 'Build' |
---|
| 19 | |
---|
| 20 | stage_name = 'Build' |
---|
| 21 | |
---|
[7359098] | 22 | //Clean the directory (Output is not relevant) |
---|
[fde808df] | 23 | sh 'make clean > /dev/null' |
---|
[7359098] | 24 | |
---|
| 25 | //Configure the conpilation (Output is not relevant) |
---|
| 26 | //Use the current directory as the installation target so nothing |
---|
| 27 | //escapes the sandbox |
---|
| 28 | //Also specify the compiler by hand |
---|
| 29 | def install_dir = pwd tmp: true |
---|
| 30 | sh "CC=gcc-4.9 CXX=g++-4.9 ./configure --prefix=${install_dir} > /dev/null" |
---|
| 31 | |
---|
| 32 | //Compile the project |
---|
| 33 | sh 'make -j 8 install' |
---|
[fde808df] | 34 | |
---|
| 35 | stage 'Test' |
---|
| 36 | |
---|
| 37 | stage_name = 'Test' |
---|
| 38 | |
---|
[84f53b4] | 39 | dir ('src/examples') { |
---|
[fde808df] | 40 | sh './runTests.sh' |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | stage 'Cleanup' |
---|
| 44 | |
---|
[d189e11] | 45 | //install doesn't need to be cleaned since prefix uses temporary workspace |
---|
[f43a200] | 46 | } |
---|
| 47 | |
---|
[fde808df] | 48 | catch (Exception caughtError) { |
---|
| 49 | err = caughtError |
---|
[b287f67] | 50 | log_needed = true |
---|
[1e44b60] | 51 | currentBuild.result = "FAILURE" |
---|
[fde808df] | 52 | |
---|
[84f53b4] | 53 | switch(stage_name) { |
---|
[fde808df] | 54 | case 'Test' : |
---|
| 55 | currentBuild.result = "TEST FAILURE" |
---|
| 56 | break |
---|
| 57 | default : |
---|
| 58 | break |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | finally { |
---|
| 63 | //Send email with final results |
---|
| 64 | email(currentBuild.result, log_needed) |
---|
| 65 | |
---|
| 66 | /* Must re-throw exception to propagate error */ |
---|
| 67 | if (err) { |
---|
| 68 | throw err |
---|
| 69 | } |
---|
[d3d0069] | 70 | } |
---|
[7aebc62] | 71 | } |
---|
[f2b977a] | 72 | |
---|
[19ad15b] | 73 | def email(String status, boolean log) { |
---|
[e8a22a7] | 74 | //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line |
---|
| 75 | //Configurations for email format |
---|
| 76 | def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase() |
---|
| 77 | |
---|
[bb5a0bb] | 78 | def email_subject = "[${project_name} git] UNNAMED PROJECT branch ${env.BRANCH_NAME} - Build # ${env.BUILD_NUMBER} - ${status}!" |
---|
[ed091cd] | 79 | def email_body = """ This is an automated email from the Jenkins build machine. It was |
---|
[e8a22a7] | 80 | generated because of a git hooks/post-receive script following |
---|
| 81 | a ref change was pushed to the repository containing |
---|
| 82 | the project "UNNAMED PROJECT". |
---|
| 83 | |
---|
[ed091cd] | 84 | The branch ${env.BRANCH_NAME} has been updated. |
---|
[e8a22a7] | 85 | |
---|
| 86 | Check console output at ${env.BUILD_URL} to view the results.""" |
---|
| 87 | |
---|
[a6b7480] | 88 | // def config = new File('/u/cforall/software/cfa/cfa-cc/config').text |
---|
| 89 | // def email_to = (config =~ /mailinglist ?= ?(.+)/)[0][1] |
---|
| 90 | def email_to = "pabuhr@uwaterloo.ca, rschlunt@uwaterloo.ca, a3moss@uwaterloo.ca, tdelisle@uwaterloo.ca, brice.dobry@huawei.com" |
---|
[e8a22a7] | 91 | |
---|
| 92 | //send email notification |
---|
[1e34653] | 93 | emailext body: email_body, subject: email_subject, to: email_to, attachLog: log |
---|
[e8a22a7] | 94 | } |
---|