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 | if(result.result == 'SUCCESS') {
|
---|
20 | echo(result.result)
|
---|
21 | }
|
---|
22 | else {
|
---|
23 | error(result.result)
|
---|
24 | sh("wget -q -O - ${result.absoluteUrl}/consoleText")
|
---|
25 | }
|
---|
26 | }
|
---|
27 |
|
---|
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 |
|
---|
37 | //checkout the code to make sure this is a valid git repo
|
---|
38 | checkout scm
|
---|
39 |
|
---|
40 | collect_git_info()
|
---|
41 |
|
---|
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 |
|
---|
51 | //sh "GIT_SSH_COMMAND=\"ssh -v\" git push DoLang ${gitRefNewValue}:master"
|
---|
52 | echo('BUILD NOT PUSH SINCE DO-LANG SERVER WAS DOWN')
|
---|
53 | }
|
---|
54 |
|
---|
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
|
---|
63 | dir("../Cforall_Full_Build@script") {
|
---|
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 |
|
---|
71 | //===========================================================================================================
|
---|
72 | // Main loop of the compilation
|
---|
73 | //===========================================================================================================
|
---|
74 |
|
---|
75 | node ('master') {
|
---|
76 | def err = null
|
---|
77 |
|
---|
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 |
|
---|
89 | parallel (
|
---|
90 | x64: {
|
---|
91 | trigger_build('64-bit')
|
---|
92 | },
|
---|
93 | x32: {
|
---|
94 | trigger_build('32-bit')
|
---|
95 | }
|
---|
96 | )
|
---|
97 |
|
---|
98 | //Push latest changes to do-lang repo
|
---|
99 | push_build()
|
---|
100 | }
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
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) {
|
---|
107 | echo('error caught')
|
---|
108 |
|
---|
109 | //rethrow error later
|
---|
110 | err = caughtError
|
---|
111 |
|
---|
112 | //Store the result of the build log
|
---|
113 | currentBuild.result = 'FAILURE'
|
---|
114 |
|
---|
115 | //Send email to notify the failure
|
---|
116 | promote_failure_email()
|
---|
117 | }
|
---|
118 |
|
---|
119 | finally {
|
---|
120 | //Must re-throw exception to propagate error
|
---|
121 | if (err) {
|
---|
122 | throw err
|
---|
123 | }
|
---|
124 | }
|
---|
125 | }
|
---|
126 | //===========================================================================================================
|
---|
127 | //Routine responsible of sending the email notification once the build is completed
|
---|
128 | //===========================================================================================================
|
---|
129 |
|
---|
130 | //Email notification on a full build failure
|
---|
131 | def promote_failure_email() {
|
---|
132 | echo('notifying users')
|
---|
133 |
|
---|
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 |
|
---|
146 | PROMOTE FAILURE
|
---|
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 | }
|
---|