[ae28ee2] | 1 | #!groovy
|
---|
| 2 |
|
---|
| 3 | //===========================================================================================================
|
---|
| 4 | // Main loop of the compilation
|
---|
| 5 | //===========================================================================================================
|
---|
| 6 |
|
---|
| 7 | node ('master') {
|
---|
| 8 | def err = null
|
---|
| 9 |
|
---|
| 10 | try {
|
---|
| 11 | //Prevent the build from exceeding 30 minutes
|
---|
| 12 | timeout(60) {
|
---|
| 13 |
|
---|
| 14 | //Wrap build to add timestamp to command line
|
---|
| 15 | wrap([$class: 'TimestamperBuildWrapper']) {
|
---|
| 16 |
|
---|
| 17 | stage 'Build'
|
---|
| 18 |
|
---|
| 19 | results = [null, null]
|
---|
| 20 |
|
---|
| 21 | parallel (
|
---|
| 22 | x64: {
|
---|
| 23 | trigger_build('64-bit')
|
---|
| 24 | },
|
---|
| 25 | x32: {
|
---|
| 26 | trigger_build('32-bit')
|
---|
| 27 | }
|
---|
| 28 | )
|
---|
| 29 |
|
---|
| 30 | //Push latest changes to do-lang repo
|
---|
| 31 | push_build()
|
---|
| 32 | }
|
---|
| 33 | }
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | //If an exception is caught we need to change the status and remember to
|
---|
| 37 | //attach the build log to the email
|
---|
| 38 | catch (Exception caughtError) {
|
---|
| 39 | echo('error caught')
|
---|
| 40 |
|
---|
| 41 | //rethrow error later
|
---|
| 42 | err = caughtError
|
---|
| 43 |
|
---|
| 44 | //Store the result of the build log
|
---|
| 45 | currentBuild.result = 'FAILURE'
|
---|
| 46 |
|
---|
| 47 | //Send email to notify the failure
|
---|
| 48 | promote_failure_email()
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | finally {
|
---|
| 52 | //Must re-throw exception to propagate error
|
---|
| 53 | if (err) {
|
---|
| 54 | throw err
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 | //===========================================================================================================
|
---|
| 59 | // Main compilation routines
|
---|
| 60 | //===========================================================================================================
|
---|
| 61 |
|
---|
| 62 | def trigger_build(String arch) {
|
---|
| 63 | def result = build job: 'Cforall/master', \
|
---|
| 64 | parameters: [ \
|
---|
| 65 | [$class: 'BooleanParameterValue', \
|
---|
| 66 | name: 'isFullBuild', \
|
---|
| 67 | value: true], \
|
---|
| 68 | [$class: 'StringParameterValue', \
|
---|
| 69 | name: 'buildArchitecture', \
|
---|
| 70 | value: arch] \
|
---|
| 71 | ], \
|
---|
| 72 | propagate: false
|
---|
| 73 |
|
---|
| 74 | echo(result.result)
|
---|
| 75 |
|
---|
| 76 | if(result.result != 'SUCCESS') {
|
---|
| 77 | sh("wget -q -O - ${result.absoluteUrl}/consoleText")
|
---|
| 78 | error(result.result)
|
---|
| 79 | }
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | def push_build() {
|
---|
| 83 | //Don't use the build_stage function which outputs the compiler
|
---|
| 84 | stage 'Push'
|
---|
| 85 |
|
---|
| 86 | status_prefix = 'Push'
|
---|
| 87 |
|
---|
| 88 | def out_dir = pwd tmp: true
|
---|
| 89 | sh "mkdir -p ${out_dir}"
|
---|
| 90 |
|
---|
| 91 | //checkout the code to make sure this is a valid git repo
|
---|
| 92 | checkout scm
|
---|
| 93 |
|
---|
| 94 | collect_git_info()
|
---|
| 95 |
|
---|
| 96 | //parse git logs to find what changed
|
---|
| 97 | sh "git remote > ${out_dir}/GIT_REMOTE"
|
---|
| 98 | git_remote = readFile("${out_dir}/GIT_REMOTE")
|
---|
| 99 | remoteDoLangExists = git_remote.contains("DoLang")
|
---|
| 100 |
|
---|
| 101 | if( !remoteDoLangExists ) {
|
---|
| 102 | sh 'git remote add DoLang git@gitlab.do-lang.org:internal/cfa-cc.git'
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | //sh "GIT_SSH_COMMAND=\"ssh -v\" git push DoLang ${gitRefNewValue}:master"
|
---|
| 106 | echo('BUILD NOT PUSH SINCE DO-LANG SERVER WAS DOWN')
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | //Helper routine to collect information about the git history
|
---|
| 110 | def collect_git_info() {
|
---|
| 111 |
|
---|
| 112 | //create the temporary output directory in case it doesn't already exist
|
---|
| 113 | def out_dir = pwd tmp: true
|
---|
| 114 | sh "mkdir -p ${out_dir}"
|
---|
| 115 |
|
---|
| 116 | //parse git logs to find what changed
|
---|
| 117 | dir("../Cforall_Full_Build@script") {
|
---|
| 118 | sh "git reflog > ${out_dir}/GIT_COMMIT"
|
---|
| 119 | }
|
---|
| 120 | git_reflog = readFile("${out_dir}/GIT_COMMIT")
|
---|
| 121 | gitRefOldValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][1]
|
---|
| 122 | gitRefNewValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][2]
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | //===========================================================================================================
|
---|
| 126 | //Routine responsible of sending the email notification once the build is completed
|
---|
| 127 | //===========================================================================================================
|
---|
| 128 |
|
---|
| 129 | //Email notification on a full build failure
|
---|
| 130 | def promote_failure_email() {
|
---|
| 131 | echo('notifying users')
|
---|
| 132 |
|
---|
| 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 |
|
---|
| 145 | PROMOTE FAILURE
|
---|
| 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 | }
|
---|