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