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