source: Jenkinsfile@ 95fdb0a

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new stuck-waitfor-destruct with_gc
Last change on this file since 95fdb0a was 95fdb0a, checked in by Thierry Delisle <tdelisle@…>, 9 years ago

Refectored jenkins file to be much more modular

  • Property mode set to 100644
File size: 8.8 KB
RevLine 
[a63ad80]1#!groovy
2
[29f4fe62]3//===========================================================================================================
[9beae23]4// Main loop of the compilation
[29f4fe62]5//===========================================================================================================
[9beae23]6node ('master'){
[56a9ce6]7
[9beae23]8 boolean bIsSandbox = env.BRANCH_NAME == "jenkins-sandbox"
9 def err = null
10 def log_needed = false
[0ef06b6]11
[95fdb0a]12 compiler = compiler_from_params()
13 architecture = architecture_from_params()
14
15 do_alltests = param_allTests .toBoolean()
16 do_benchmark = param_benchmark .toBoolean()
17 do_doc = param_doc .toBoolean()
18 do_publish
[56a9ce6]19
[0ef06b6]20 currentBuild.result = "SUCCESS"
21
[9beae23]22 try {
[95fdb0a]23 //Wrap build to add timestamp to command line
24 wrap([$class: 'TimestamperBuildWrapper']) {
[23a14d86]25
[95fdb0a]26 //Prevent the build from exceeding 60 minutes
27 timeout(60) {
28
29 notify()
[7aebc62]30
[0ef06b6]31 prepare_build()
[fde808df]32
[95fdb0a]33 checkout()
34
35 build()
36
37 test()
38
39 benchmark()
[7359098]40
[95fdb0a]41 clean()
[7359098]42
[95fdb0a]43 build_doc()
[9beae23]44
[95fdb0a]45 publish()
46
47 notify()
[9beae23]48 }
49 }
[738cf8f]50 }
51
[9beae23]52 //If an exception is caught we need to change the status and remember to
53 //attach the build log to the email
[738cf8f]54 catch (Exception caughtError) {
55 //rethrow error later
56 err = caughtError
57
[9beae23]58 //An error has occured, the build log is relevent
59 log_needed = true
60
61 //Store the result of the build log
62 currentBuild.result = "${status_prefix} FAILURE".trim()
[738cf8f]63 }
64
65 finally {
[9beae23]66 echo 'Build Completed'
67
68 //Send email with final results if this is not a full build
[95fdb0a]69 if( !do_sendemail && !bIsSandbox ) {
[9beae23]70 echo 'Notifying users of result'
71 email(currentBuild.result, log_needed)
72 }
73
[738cf8f]74 /* Must re-throw exception to propagate error */
75 if (err) {
76 throw err
77 }
78 }
79}
80
[29f4fe62]81//===========================================================================================================
[95fdb0a]82// Helper classes/variables/routines
[29f4fe62]83//===========================================================================================================
[e730560]84//Description of a compiler (Must be serializable since pipelines are persistent)
85class CC_Desc implements Serializable {
[8f6b229]86 public String cc_name
87 public String cpp_cc
88 public String cfa_backend_cc
[f25bcb6]89
90 CC_Desc(String cc_name, String cpp_cc, String cfa_backend_cc) {
91 this.cc_name = cc_name
92 this.cpp_cc = cpp_cc
93 this.cfa_backend_cc = cfa_backend_cc
94 }
[992c26d]95}
96
[ab60d6d]97//Helper routine to collect information about the git history
98def collect_git_info() {
99
[abc26975]100 //create the temporary output directory in case it doesn't already exist
[ab60d6d]101 def out_dir = pwd tmp: true
[abc26975]102 sh "mkdir -p ${out_dir}"
103
104 //parse git logs to find what changed
[ab60d6d]105 gitRefName = env.BRANCH_NAME
106 dir("../${gitRefName}@script") {
107 sh "git reflog > ${out_dir}/GIT_COMMIT"
108 }
109 git_reflog = readFile("${out_dir}/GIT_COMMIT")
110 gitRefOldValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][1]
111 gitRefNewValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][2]
112}
113
[0ef06b6]114def prepare_build() {
[95fdb0a]115 properties ([ \
116 [$class: 'ParametersDefinitionProperty', \
117 parameterDefinitions: [ \
118 [$class: 'ChoiceParameterDefinition', \
119 description: 'Which compiler to use', \
120 name: 'param_compiler', \
121 choices: 'gcc-6\ngcc-5\ngcc-4.9\nclang', \
122 defaultValue: 'gcc-6', \
123 ], \
124 [$class: 'ChoiceParameterDefinition', \
125 description: 'The target architecture', \
126 name: 'param_arch', \
127 choices: '64-bit\n32-bit', \
128 defaultValue: '64-bit', \
129 ], \
130 [$class: 'BooleanParameterDefinition', \
131 description: 'If false, only the quick test suite is ran', \
132 name: 'param_allTests', \
133 defaultValue: false, \
134 ], \
135 [$class: 'BooleanParameterDefinition', \
136 description: 'If true, jenkins also runs benchmarks', \
137 name: 'param_benchmark', \
138 defaultValue: false, \
139 ], \
140 [$class: 'BooleanParameterDefinition', \
141 description: 'If true, jenkins also builds documentation', \
142 name: 'param_doc', \
143 defaultValue: false, \
144 ], \
145 [$class: 'BooleanParameterDefinition', \
146 description: 'If true, jenkins also publishes results', \
147 name: 'param_publish', \
148 defaultValue: false, \
149 ], \
150 ],
[0ef06b6]151 ]])
152
[95fdb0a]153 compiler = compiler_from_params()
154 architecture = architecture_from_params()
[0ef06b6]155
[95fdb0a]156 do_alltests = param_allTests .toBoolean()
157 do_benchmark = param_benchmark .toBoolean()
158 do_doc = param_doc .toBoolean()
159 do_publish = param_publish .toBoolean()
[0ef06b6]160
161 collect_git_info()
[95fdb0a]162}
[0ef06b6]163
[95fdb0a]164def notify() {
165 sh 'curl --data "" http://plg2:8082/jenkins/notify'
166}
167
168def make_doc() {
169 def err = null
170 try {
171 sh 'make clean > /dev/null'
172 sh 'make > /dev/null 2>&1'
173 }
174 catch (Exception caughtError) {
175 err = caughtError //rethrow error later
176 sh 'cat *.log'
177 }
178 finally {
179 if (err) throw err // Must re-throw exception to propagate error
180 }
[0ef06b6]181}
182
[29f4fe62]183//===========================================================================================================
[9beae23]184// Main compilation routines
[29f4fe62]185//===========================================================================================================
[9beae23]186//Compilation script is done here but environnement set-up and error handling is done in main loop
[95fdb0a]187def checkout() {
188 stage 'Checkout'
[9beae23]189 //checkout the source code and clean the repo
190 checkout scm
[77f347d]191
[9beae23]192 //Clean all temporary files to make sure no artifacts of the previous build remain
193 sh 'git clean -fdqx'
[40b1df9]194
[9beae23]195 //Reset the git repo so no local changes persist
196 sh 'git reset --hard'
[95fdb0a]197}
[29f4fe62]198
[95fdb0a]199def build() {
200 stage 'Build'
201
202 def install_dir = pwd tmp: true
203
[9beae23]204 //Configure the conpilation (Output is not relevant)
205 //Use the current directory as the installation target so nothing
206 //escapes the sandbox
207 //Also specify the compiler by hand
[95fdb0a]208 sh "./configure CXX=${compiler.cpp_cc} ${architecture} --with-backend-compiler=${compiler.cfa_backend_cc} --prefix=${install_dir} --enable-silent-rules --quiet"
[9e5f409]209
[9beae23]210 //Compile the project
211 sh 'make -j 8 --no-print-directory V=0 install'
[95fdb0a]212}
[24eecab]213
[95fdb0a]214def test() {
215 stage 'Test'
[9e5f409]216
[9beae23]217 //Run the tests from the tests directory
[95fdb0a]218 if ( do_alltests ) {
[9beae23]219 sh 'make -C src/tests all-tests debug=yes'
220 sh 'make -C src/tests all-tests debug=no'
221 }
222 else {
223 sh 'make -C src/tests'
224 }
[95fdb0a]225}
226
227def benchmark() {
228 stage 'Benchmark'
[29f4fe62]229
[95fdb0a]230 if( !do_bencmark ) return
[ae28ee2]231
232 //Write the commit id to Benchmark
[f9fa306]233 writeFile file: 'bench.csv', text:'data=' + gitRefNewValue + ','
[ae28ee2]234
235 //Append bench results
[f9fa306]236 sh 'make -C src/benchmark --no-print-directory csv-data >> bench.csv'
[95fdb0a]237}
[ae28ee2]238
[95fdb0a]239def clean() {
240 stage 'Cleanup'
[d56c05d0]241
[9beae23]242 //do a maintainer-clean to make sure we need to remake from scratch
243 sh 'make maintainer-clean > /dev/null'
244}
[efd60d67]245
[95fdb0a]246def build_doc() {
[9beae23]247 stage 'Documentation'
248
[95fdb0a]249 if( !do_doc ) return
[9beae23]250
251 dir ('doc/user') {
252 make_doc()
253 }
254
255 dir ('doc/refrat') {
256 make_doc()
257 }
258}
259
[95fdb0a]260def publish() {
261 stage 'Publish'
262
263 if( !do_publish ) return
264
265 //Then publish the results
266 sh 'curl --data @bench.csv http://plg2:8082/jenkins/publish'
267}
268
[29f4fe62]269//===========================================================================================================
270//Routine responsible of sending the email notification once the build is completed
271//===========================================================================================================
[a235d09]272//Standard build email notification
[19ad15b]273def email(String status, boolean log) {
[e8a22a7]274 //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
275 //Configurations for email format
276 def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase()
277
[0a346e5]278 def gitLog = 'Error retrieving git logs'
279 def gitDiff = 'Error retrieving git diff'
[7b1a604]280
[0a346e5]281 try {
282
283 sh "git rev-list --format=short ${gitRefOldValue}...${gitRefNewValue} > GIT_LOG"
284 gitLog = readFile('GIT_LOG')
285
286 sh "git diff --stat ${gitRefNewValue} ${gitRefOldValue} > GIT_DIFF"
287 gitDiff = readFile('GIT_DIFF')
288 }
289 catch (Exception error) {}
[7b1a604]290
[992c26d]291 def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${status}] - branch ${env.BRANCH_NAME}"
[848fb00]292 def email_body = """This is an automated email from the Jenkins build machine. It was
293generated because of a git hooks/post-receive script following
294a ref change was pushed to the repository containing
295the project "UNNAMED PROJECT".
[e8a22a7]296
[848fb00]297The branch ${env.BRANCH_NAME} has been updated.
[a235d09]298 via ${gitRefOldValue} (commit)
299 from ${gitRefNewValue} (commit)
[7b1a604]300
301Check console output at ${env.BUILD_URL} to view the results.
302
303- Status --------------------------------------------------------------
304
305BUILD# ${env.BUILD_NUMBER} - ${status}
[e8a22a7]306
[7b1a604]307- Log -----------------------------------------------------------------
308${gitLog}
309-----------------------------------------------------------------------
310Summary of changes:
311${gitDiff}
312"""
[e8a22a7]313
[a6b7480]314 def email_to = "pabuhr@uwaterloo.ca, rschlunt@uwaterloo.ca, a3moss@uwaterloo.ca, tdelisle@uwaterloo.ca, brice.dobry@huawei.com"
[e8a22a7]315
316 //send email notification
[1e34653]317 emailext body: email_body, subject: email_subject, to: email_to, attachLog: log
[e8a22a7]318}
Note: See TracBrowser for help on using the repository browser.