[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', \ |
---|
[5ee0482] | 9 | parameters: [ \ |
---|
[5ed9061] | 10 | [$class: 'BooleanParameterValue', \ |
---|
| 11 | name: 'isFullBuild', \ |
---|
| 12 | value: true], \ |
---|
| 13 | [$class: 'StringParameterValue', \ |
---|
| 14 | name: 'buildArchitecture', \ |
---|
[a2c5c17] | 15 | value: arch] \ |
---|
| 16 | ], \ |
---|
[5ee0482] | 17 | propagate: false |
---|
[5ed9061] | 18 | |
---|
[5a11e07] | 19 | echo(result.result) |
---|
| 20 | |
---|
| 21 | if(result.result != 'SUCCESS') { |
---|
[d2f5469] | 22 | sh("wget -q -O - ${result.absoluteUrl}/consoleText") |
---|
[5a11e07] | 23 | error(result.result) |
---|
[d2f5469] | 24 | } |
---|
[5ed9061] | 25 | } |
---|
| 26 | |
---|
[1b8c156] | 27 | def push_build() { |
---|
| 28 | //Don't use the build_stage function which outputs the compiler |
---|
| 29 | stage 'Push' |
---|
| 30 | |
---|
| 31 | status_prefix = 'Push' |
---|
| 32 | |
---|
| 33 | def out_dir = pwd tmp: true |
---|
| 34 | sh "mkdir -p ${out_dir}" |
---|
| 35 | |
---|
[cb2e8ce] | 36 | //checkout the code to make sure this is a valid git repo |
---|
| 37 | checkout scm |
---|
| 38 | |
---|
[920725d] | 39 | collect_git_info() |
---|
| 40 | |
---|
[1b8c156] | 41 | //parse git logs to find what changed |
---|
| 42 | sh "git remote > ${out_dir}/GIT_REMOTE" |
---|
| 43 | git_remote = readFile("${out_dir}/GIT_REMOTE") |
---|
| 44 | remoteDoLangExists = git_remote.contains("DoLang") |
---|
| 45 | |
---|
| 46 | if( !remoteDoLangExists ) { |
---|
| 47 | sh 'git remote add DoLang git@gitlab.do-lang.org:internal/cfa-cc.git' |
---|
| 48 | } |
---|
| 49 | |
---|
[e21c72d] | 50 | //sh "GIT_SSH_COMMAND=\"ssh -v\" git push DoLang ${gitRefNewValue}:master" |
---|
| 51 | echo('BUILD NOT PUSH SINCE DO-LANG SERVER WAS DOWN') |
---|
[1b8c156] | 52 | } |
---|
| 53 | |
---|
[920725d] | 54 | //Helper routine to collect information about the git history |
---|
| 55 | def collect_git_info() { |
---|
| 56 | |
---|
| 57 | //create the temporary output directory in case it doesn't already exist |
---|
| 58 | def out_dir = pwd tmp: true |
---|
| 59 | sh "mkdir -p ${out_dir}" |
---|
| 60 | |
---|
| 61 | //parse git logs to find what changed |
---|
[284b7aa] | 62 | dir("../Cforall_Full_Build@script") { |
---|
[920725d] | 63 | sh "git reflog > ${out_dir}/GIT_COMMIT" |
---|
| 64 | } |
---|
| 65 | git_reflog = readFile("${out_dir}/GIT_COMMIT") |
---|
| 66 | gitRefOldValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][1] |
---|
| 67 | gitRefNewValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][2] |
---|
| 68 | } |
---|
| 69 | |
---|
[6003581] | 70 | //=========================================================================================================== |
---|
| 71 | // Main loop of the compilation |
---|
| 72 | //=========================================================================================================== |
---|
[121f499] | 73 | |
---|
[ad5b73e] | 74 | node ('master') { |
---|
[155cce0f] | 75 | def err = null |
---|
| 76 | |
---|
[ad5b73e] | 77 | try { |
---|
| 78 | //Prevent the build from exceeding 30 minutes |
---|
| 79 | timeout(60) { |
---|
| 80 | |
---|
| 81 | //Wrap build to add timestamp to command line |
---|
| 82 | wrap([$class: 'TimestamperBuildWrapper']) { |
---|
| 83 | |
---|
| 84 | stage 'Build' |
---|
| 85 | |
---|
| 86 | results = [null, null] |
---|
| 87 | |
---|
[155cce0f] | 88 | parallel ( |
---|
| 89 | x64: { |
---|
| 90 | trigger_build('64-bit') |
---|
| 91 | }, |
---|
| 92 | x32: { |
---|
| 93 | trigger_build('32-bit') |
---|
| 94 | } |
---|
| 95 | ) |
---|
[ad5b73e] | 96 | |
---|
| 97 | //Push latest changes to do-lang repo |
---|
| 98 | push_build() |
---|
| 99 | } |
---|
[6003581] | 100 | } |
---|
| 101 | } |
---|
| 102 | |
---|
[121f499] | 103 | //If an exception is caught we need to change the status and remember to |
---|
| 104 | //attach the build log to the email |
---|
| 105 | catch (Exception caughtError) { |
---|
[e109716] | 106 | echo('error caught') |
---|
| 107 | |
---|
[121f499] | 108 | //rethrow error later |
---|
| 109 | err = caughtError |
---|
[6003581] | 110 | |
---|
[121f499] | 111 | //Store the result of the build log |
---|
[5ae36ed] | 112 | currentBuild.result = 'FAILURE' |
---|
[6003581] | 113 | |
---|
[121f499] | 114 | //Send email to notify the failure |
---|
[5ae36ed] | 115 | promote_failure_email() |
---|
[6003581] | 116 | } |
---|
| 117 | |
---|
[121f499] | 118 | finally { |
---|
| 119 | //Must re-throw exception to propagate error |
---|
| 120 | if (err) { |
---|
| 121 | throw err |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | } |
---|
[6003581] | 125 | //=========================================================================================================== |
---|
| 126 | //Routine responsible of sending the email notification once the build is completed |
---|
| 127 | //=========================================================================================================== |
---|
[1b8c156] | 128 | |
---|
| 129 | //Email notification on a full build failure |
---|
[5ae36ed] | 130 | def promote_failure_email() { |
---|
[e109716] | 131 | echo('notifying users') |
---|
| 132 | |
---|
[1b8c156] | 133 | //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line |
---|
| 134 | //Configurations for email format |
---|
| 135 | def email_subject = "[cforall git][PROMOTE - FAILURE]" |
---|
| 136 | def email_body = """This is an automated email from the Jenkins build machine. It was |
---|
| 137 | generated because of a git hooks/post-receive script following |
---|
| 138 | a ref change was pushed to the repository containing |
---|
| 139 | the project "UNNAMED PROJECT". |
---|
| 140 | |
---|
| 141 | Check console output at ${env.BUILD_URL} to view the results. |
---|
| 142 | |
---|
| 143 | - Status -------------------------------------------------------------- |
---|
| 144 | |
---|
[5ae36ed] | 145 | PROMOTE FAILURE |
---|
[1b8c156] | 146 | """ |
---|
| 147 | |
---|
| 148 | def email_to = "pabuhr@uwaterloo.ca, rschlunt@uwaterloo.ca, a3moss@uwaterloo.ca, tdelisle@uwaterloo.ca, brice.dobry@huawei.com" |
---|
| 149 | |
---|
| 150 | //send email notification |
---|
| 151 | emailext body: email_body, subject: email_subject, to: email_to, attachLog: true |
---|
| 152 | } |
---|