| 1 |
|
|---|
| 2 |
|
|---|
| 3 | node ('master'){
|
|---|
| 4 |
|
|---|
| 5 | def err = null
|
|---|
| 6 | def stage_name
|
|---|
| 7 | def log_needed = false
|
|---|
| 8 | currentBuild.result = "SUCCESS"
|
|---|
| 9 |
|
|---|
| 10 | try {
|
|---|
| 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 |
|
|---|
| 22 | //configure the conpilation
|
|---|
| 23 | //Don't remove outputs for the clean and configure unless errors are present
|
|---|
| 24 | sh 'make clean > /dev/null'
|
|---|
| 25 | sh 'CC=gcc-4.9 CXX=g++-4.9 ./configure > /dev/null'
|
|---|
| 26 | sh 'make -j 8'
|
|---|
| 27 |
|
|---|
| 28 | stage 'Test'
|
|---|
| 29 |
|
|---|
| 30 | stage_name = 'Test'
|
|---|
| 31 |
|
|---|
| 32 | dir ('src/example') {
|
|---|
| 33 | sh './runTests.sh'
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | stage 'Cleanup'
|
|---|
| 37 |
|
|---|
| 38 | email("SUCCESS", false)
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | catch (Exception caughtError) {
|
|---|
| 42 | err = caughtError
|
|---|
| 43 |
|
|---|
| 44 | switch(stage) {
|
|---|
| 45 | case 'Test' :
|
|---|
| 46 | currentBuild.result = "TEST FAILURE"
|
|---|
| 47 | break
|
|---|
| 48 | default :
|
|---|
| 49 | currentBuild.result = "FAILURE"
|
|---|
| 50 | break
|
|---|
| 51 | }
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | finally {
|
|---|
| 55 | //Send email with final results
|
|---|
| 56 | email(currentBuild.result, log_needed)
|
|---|
| 57 |
|
|---|
| 58 | /* Must re-throw exception to propagate error */
|
|---|
| 59 | if (err) {
|
|---|
| 60 | throw err
|
|---|
| 61 | }
|
|---|
| 62 | }
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | def email(String status, boolean log) {
|
|---|
| 66 | //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
|
|---|
| 67 | //Configurations for email format
|
|---|
| 68 | def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase()
|
|---|
| 69 |
|
|---|
| 70 | def email_subject = "[${project_name} git] UNNAMED PROJECT branch ${env.BRANCH_NAME} - Build # ${env.BUILD_NUMBER} - ${status}!"
|
|---|
| 71 | def email_body = """ This is an automated email from the Jenkins build machine. It was
|
|---|
| 72 | generated because of a git hooks/post-receive script following
|
|---|
| 73 | a ref change was pushed to the repository containing
|
|---|
| 74 | the project "UNNAMED PROJECT".
|
|---|
| 75 |
|
|---|
| 76 | The branch ${env.BRANCH_NAME} has been updated.
|
|---|
| 77 |
|
|---|
| 78 | Check console output at ${env.BUILD_URL} to view the results."""
|
|---|
| 79 |
|
|---|
| 80 | // def config = new File('/u/cforall/software/cfa/cfa-cc/config').text
|
|---|
| 81 | // def email_to = (config =~ /mailinglist ?= ?(.+)/)[0][1]
|
|---|
| 82 | def email_to = "pabuhr@uwaterloo.ca, rschlunt@uwaterloo.ca, a3moss@uwaterloo.ca, tdelisle@uwaterloo.ca, brice.dobry@huawei.com"
|
|---|
| 83 |
|
|---|
| 84 | //send email notification
|
|---|
| 85 | emailext body: email_body, subject: email_subject, to: email_to, attachLog: log
|
|---|
| 86 | }
|
|---|