1 | //=========================================================================================================== |
---|
2 | // Main compilation routine |
---|
3 | //=========================================================================================================== |
---|
4 | //Compilation script is done here but environnement set-up and error handling is done in main loop |
---|
5 | def cfa_build() { |
---|
6 | build_stage 'Checkout' |
---|
7 | def install_dir = pwd tmp: true |
---|
8 | //checkout the source code and clean the repo |
---|
9 | checkout scm |
---|
10 | sh 'git clean -fdqx' |
---|
11 | sh 'git reset --hard' |
---|
12 | |
---|
13 | build_stage 'Build' |
---|
14 | |
---|
15 | //Configure the conpilation (Output is not relevant) |
---|
16 | //Use the current directory as the installation target so nothing |
---|
17 | //escapes the sandbox |
---|
18 | //Also specify the compiler by hand |
---|
19 | sh "./configure CXX=${currentCC.cpp_cc} --with-backend-compiler=${currentCC.cfa_backend_cc} --prefix=${install_dir} > /dev/null" |
---|
20 | |
---|
21 | //Compile the project |
---|
22 | sh 'make -j 8 install' |
---|
23 | |
---|
24 | build_stage 'Test' |
---|
25 | |
---|
26 | //Run the tests from the example directory |
---|
27 | dir ('src/examples') { |
---|
28 | sh './runTests.sh' |
---|
29 | } |
---|
30 | |
---|
31 | build_stage 'Cleanup' |
---|
32 | |
---|
33 | //do a maintainer-clean to make sure we need to remake from scratch |
---|
34 | sh 'make maintainer-clean > /dev/null' |
---|
35 | } |
---|
36 | |
---|
37 | def push_build() { |
---|
38 | build_stage 'Push' |
---|
39 | |
---|
40 | sh 'git remote add DoLang git@gitlab.do-lang.org:internal/cfa-cc.git' |
---|
41 | sh 'git push DoLang master' |
---|
42 | } |
---|
43 | |
---|
44 | //=========================================================================================================== |
---|
45 | // Helper classes/variables/routines to make the status and stage name easier to use |
---|
46 | //=========================================================================================================== |
---|
47 | //Description of a compiler (Must be serializable since pipelines are persistent) |
---|
48 | class CC_Desc implements Serializable { |
---|
49 | public String cc_name |
---|
50 | public String cpp_cc |
---|
51 | public String cfa_backend_cc |
---|
52 | |
---|
53 | CC_Desc(String cc_name, String cpp_cc, String cfa_backend_cc) { |
---|
54 | this.cc_name = cc_name |
---|
55 | this.cpp_cc = cpp_cc |
---|
56 | this.cfa_backend_cc = cfa_backend_cc |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | //Global Variables defining the compiler and at which point in the build we are |
---|
61 | // These variables are used but can't be declared before hand because of wierd scripting rules |
---|
62 | // @Field String currentCC |
---|
63 | // @Field String status_prefix |
---|
64 | |
---|
65 | //Wrapper to sync stage name and status name |
---|
66 | def build_stage(String name) { |
---|
67 | def stage_name = "${currentCC.cc_name} ${name}".trim() |
---|
68 | stage stage_name |
---|
69 | |
---|
70 | status_prefix = stage_name |
---|
71 | } |
---|
72 | |
---|
73 | //Helper routine to collect information about the git history |
---|
74 | def collect_git_info() { |
---|
75 | |
---|
76 | def out_dir = pwd tmp: true |
---|
77 | gitRefName = env.BRANCH_NAME |
---|
78 | dir("../${gitRefName}@script") { |
---|
79 | sh "git reflog > ${out_dir}/GIT_COMMIT" |
---|
80 | } |
---|
81 | git_reflog = readFile("${out_dir}/GIT_COMMIT") |
---|
82 | gitRefOldValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][1] |
---|
83 | gitRefNewValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][2] |
---|
84 | } |
---|
85 | |
---|
86 | //=========================================================================================================== |
---|
87 | // Main loop of the compilation |
---|
88 | //=========================================================================================================== |
---|
89 | node ('master'){ |
---|
90 | |
---|
91 | def err = null |
---|
92 | def log_needed = false |
---|
93 | currentBuild.result = "SUCCESS" |
---|
94 | status_prefix = '' |
---|
95 | |
---|
96 | try { |
---|
97 | //Prevent the build from exceeding 30 minutes |
---|
98 | timeout(30) { |
---|
99 | |
---|
100 | //Wrap build to add timestamp to command line |
---|
101 | wrap([$class: 'TimestamperBuildWrapper']) { |
---|
102 | |
---|
103 | collect_git_info() |
---|
104 | |
---|
105 | properties ([ \ |
---|
106 | [$class: 'ParametersDefinitionProperty', \ |
---|
107 | parameterDefinitions: [ \ |
---|
108 | [$class: 'BooleanParameterDefinition', \ |
---|
109 | defaultValue: false, \ |
---|
110 | description: 'If true, the build will be promoted to the do-lang git repository (on successful builds only)', \ |
---|
111 | name: 'promoteBuild2DoLang' \ |
---|
112 | ]] \ |
---|
113 | ]]) |
---|
114 | |
---|
115 | echo "FULL BUILD = ${promoteBuild2DoLang}" |
---|
116 | |
---|
117 | //Compile using gcc-4.9 |
---|
118 | currentCC = new CC_Desc('gcc-4.9', 'g++-4.9', 'gcc-4.9') |
---|
119 | cfa_build() |
---|
120 | |
---|
121 | //Compile using gcc-5 |
---|
122 | currentCC = new CC_Desc('gcc-5', 'g++-5', 'gcc-5') |
---|
123 | cfa_build() |
---|
124 | |
---|
125 | //Compile using gcc-4.9 |
---|
126 | currentCC = new CC_Desc('gcc-6', 'g++-6', 'gcc-6') |
---|
127 | cfa_build() |
---|
128 | |
---|
129 | if(promoteBuild2DoLang) { |
---|
130 | push_build() |
---|
131 | } |
---|
132 | } |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|
136 | //If an exception is caught we need to change the status and remember to |
---|
137 | //attach the build log to the email |
---|
138 | catch (Exception caughtError) { |
---|
139 | //rethrow error later |
---|
140 | err = caughtError |
---|
141 | |
---|
142 | //An error has occured, the build log is relevent |
---|
143 | log_needed = true |
---|
144 | |
---|
145 | //Store the result of the build log |
---|
146 | currentBuild.result = "${status_prefix} FAILURE".trim() |
---|
147 | } |
---|
148 | |
---|
149 | finally { |
---|
150 | //Send email with final results |
---|
151 | notify_result(promoteBuild2DoLang, err != null, currentBuild.result, log_needed) |
---|
152 | |
---|
153 | /* Must re-throw exception to propagate error */ |
---|
154 | if (err) { |
---|
155 | throw err |
---|
156 | } |
---|
157 | } |
---|
158 | } |
---|
159 | |
---|
160 | //=========================================================================================================== |
---|
161 | //Routine responsible of sending the email notification once the build is completed |
---|
162 | //=========================================================================================================== |
---|
163 | def promote_email(boolean promote, boolean success, String status, boolean log) { |
---|
164 | if(promote) { |
---|
165 | if( !success ) { |
---|
166 | promote_email(status) |
---|
167 | } |
---|
168 | } |
---|
169 | else { |
---|
170 | email(status, log) |
---|
171 | } |
---|
172 | } |
---|
173 | |
---|
174 | //Email notification on a full build failure |
---|
175 | def promote_email(String status) { |
---|
176 | //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line |
---|
177 | //Configurations for email format |
---|
178 | def email_subject = "[cforall git][PROMOTE - FAILURE]" |
---|
179 | def email_body = """This is an automated email from the Jenkins build machine. It was |
---|
180 | generated because of a git hooks/post-receive script following |
---|
181 | a ref change was pushed to the repository containing |
---|
182 | the project "UNNAMED PROJECT". |
---|
183 | |
---|
184 | Check console output at ${env.BUILD_URL} to view the results. |
---|
185 | |
---|
186 | - Status -------------------------------------------------------------- |
---|
187 | |
---|
188 | PROMOTE FAILURE - ${status} |
---|
189 | """ |
---|
190 | |
---|
191 | def email_to = "pabuhr@uwaterloo.ca, rschlunt@uwaterloo.ca, a3moss@uwaterloo.ca, tdelisle@uwaterloo.ca, brice.dobry@huawei.com" |
---|
192 | |
---|
193 | //send email notification |
---|
194 | emailext body: email_body, subject: email_subject, to: email_to, attachLog: true |
---|
195 | } |
---|
196 | |
---|
197 | //Standard build email notification |
---|
198 | def email(String status, boolean log) { |
---|
199 | //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line |
---|
200 | //Configurations for email format |
---|
201 | def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase() |
---|
202 | |
---|
203 | sh "git rev-list --format=short ${gitRefOldValue}...${gitRefNewValue} > GIT_LOG" |
---|
204 | def gitLog = readFile('GIT_LOG') |
---|
205 | |
---|
206 | sh "git diff --stat ${gitRefNewValue} ${gitRefOldValue} > GIT_DIFF" |
---|
207 | def gitDiff = readFile('GIT_DIFF') |
---|
208 | |
---|
209 | def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${status}] - branch ${env.BRANCH_NAME}" |
---|
210 | def email_body = """This is an automated email from the Jenkins build machine. It was |
---|
211 | generated because of a git hooks/post-receive script following |
---|
212 | a ref change was pushed to the repository containing |
---|
213 | the project "UNNAMED PROJECT". |
---|
214 | |
---|
215 | The branch ${env.BRANCH_NAME} has been updated. |
---|
216 | via ${gitRefOldValue} (commit) |
---|
217 | from ${gitRefNewValue} (commit) |
---|
218 | |
---|
219 | Check console output at ${env.BUILD_URL} to view the results. |
---|
220 | |
---|
221 | - Status -------------------------------------------------------------- |
---|
222 | |
---|
223 | BUILD# ${env.BUILD_NUMBER} - ${status} |
---|
224 | |
---|
225 | - Log ----------------------------------------------------------------- |
---|
226 | ${gitLog} |
---|
227 | ----------------------------------------------------------------------- |
---|
228 | Summary of changes: |
---|
229 | ${gitDiff} |
---|
230 | """ |
---|
231 | |
---|
232 | def email_to = "pabuhr@uwaterloo.ca, rschlunt@uwaterloo.ca, a3moss@uwaterloo.ca, tdelisle@uwaterloo.ca, brice.dobry@huawei.com" |
---|
233 | |
---|
234 | //send email notification |
---|
235 | emailext body: email_body, subject: email_subject, to: email_to, attachLog: log |
---|
236 | } |
---|