[1b8c156] | 1 | #!groovy |
---|
| 2 | |
---|
[6003581] | 3 | //=========================================================================================================== |
---|
| 4 | // Main compilation routines |
---|
| 5 | //=========================================================================================================== |
---|
[5ed9061] | 6 | |
---|
| 7 | def trigger_build(String arch) { |
---|
| 8 | def result = build job: 'Cforall/master', \ |
---|
| 9 | parameters: [ \ |
---|
| 10 | [$class: 'BooleanParameterValue', \ |
---|
| 11 | name: 'isFullBuild', \ |
---|
| 12 | value: true], \ |
---|
| 13 | [$class: 'StringParameterValue', \ |
---|
| 14 | name: 'buildArchitecture', \ |
---|
| 15 | value: arch] \ |
---|
| 16 | ] |
---|
| 17 | |
---|
| 18 | echo(result.result) |
---|
| 19 | echo(result.absoluteUrl) |
---|
| 20 | } |
---|
| 21 | |
---|
[1b8c156] | 22 | def push_build() { |
---|
| 23 | //Don't use the build_stage function which outputs the compiler |
---|
| 24 | stage 'Push' |
---|
| 25 | |
---|
| 26 | status_prefix = 'Push' |
---|
| 27 | |
---|
| 28 | def out_dir = pwd tmp: true |
---|
| 29 | sh "mkdir -p ${out_dir}" |
---|
| 30 | |
---|
[cb2e8ce] | 31 | //checkout the code to make sure this is a valid git repo |
---|
| 32 | checkout scm |
---|
| 33 | |
---|
[1b8c156] | 34 | //parse git logs to find what changed |
---|
| 35 | sh "git remote > ${out_dir}/GIT_REMOTE" |
---|
| 36 | git_remote = readFile("${out_dir}/GIT_REMOTE") |
---|
| 37 | remoteDoLangExists = git_remote.contains("DoLang") |
---|
| 38 | |
---|
| 39 | if( !remoteDoLangExists ) { |
---|
| 40 | sh 'git remote add DoLang git@gitlab.do-lang.org:internal/cfa-cc.git' |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | sh "git push DoLang ${gitRefNewValue}:master" |
---|
| 44 | } |
---|
| 45 | |
---|
[6003581] | 46 | //=========================================================================================================== |
---|
| 47 | // Main loop of the compilation |
---|
| 48 | //=========================================================================================================== |
---|
[121f499] | 49 | |
---|
[ad5b73e] | 50 | node ('master') { |
---|
| 51 | try { |
---|
| 52 | //Prevent the build from exceeding 30 minutes |
---|
| 53 | timeout(60) { |
---|
| 54 | |
---|
| 55 | //Wrap build to add timestamp to command line |
---|
| 56 | wrap([$class: 'TimestamperBuildWrapper']) { |
---|
| 57 | |
---|
| 58 | stage 'Build' |
---|
| 59 | |
---|
| 60 | results = [null, null] |
---|
| 61 | |
---|
| 62 | parallel ( |
---|
| 63 | x64: { |
---|
[5ed9061] | 64 | trigger_build('64-bit') |
---|
[ad5b73e] | 65 | }, |
---|
[5ed9061] | 66 | x32: { |
---|
| 67 | trigger_build('32-bit') |
---|
[ad5b73e] | 68 | } |
---|
| 69 | ) |
---|
| 70 | |
---|
| 71 | //Push latest changes to do-lang repo |
---|
| 72 | push_build() |
---|
| 73 | } |
---|
[6003581] | 74 | } |
---|
| 75 | } |
---|
| 76 | |
---|
[121f499] | 77 | //If an exception is caught we need to change the status and remember to |
---|
| 78 | //attach the build log to the email |
---|
| 79 | catch (Exception caughtError) { |
---|
| 80 | //rethrow error later |
---|
| 81 | err = caughtError |
---|
[6003581] | 82 | |
---|
[121f499] | 83 | //Store the result of the build log |
---|
| 84 | currentBuild.result = "${status_prefix} FAILURE".trim() |
---|
[6003581] | 85 | |
---|
[121f499] | 86 | //Send email to notify the failure |
---|
| 87 | promote_email(currentBuild.result) |
---|
[6003581] | 88 | } |
---|
| 89 | |
---|
[121f499] | 90 | finally { |
---|
| 91 | //Must re-throw exception to propagate error |
---|
| 92 | if (err) { |
---|
| 93 | throw err |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | } |
---|
[6003581] | 97 | //=========================================================================================================== |
---|
| 98 | //Routine responsible of sending the email notification once the build is completed |
---|
| 99 | //=========================================================================================================== |
---|
[1b8c156] | 100 | |
---|
| 101 | //Email notification on a full build failure |
---|
| 102 | def promote_email(String status) { |
---|
| 103 | //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line |
---|
| 104 | //Configurations for email format |
---|
| 105 | def email_subject = "[cforall git][PROMOTE - FAILURE]" |
---|
| 106 | def email_body = """This is an automated email from the Jenkins build machine. It was |
---|
| 107 | generated because of a git hooks/post-receive script following |
---|
| 108 | a ref change was pushed to the repository containing |
---|
| 109 | the project "UNNAMED PROJECT". |
---|
| 110 | |
---|
| 111 | Check console output at ${env.BUILD_URL} to view the results. |
---|
| 112 | |
---|
| 113 | - Status -------------------------------------------------------------- |
---|
| 114 | |
---|
| 115 | PROMOTE FAILURE - ${status} |
---|
| 116 | """ |
---|
| 117 | |
---|
| 118 | def email_to = "pabuhr@uwaterloo.ca, rschlunt@uwaterloo.ca, a3moss@uwaterloo.ca, tdelisle@uwaterloo.ca, brice.dobry@huawei.com" |
---|
| 119 | |
---|
| 120 | //send email notification |
---|
| 121 | emailext body: email_body, subject: email_subject, to: email_to, attachLog: true |
---|
| 122 | } |
---|