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