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