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