source: Jenkinsfile @ 95fdb0a

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 95fdb0a was 95fdb0a, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Refectored jenkins file to be much more modular

  • Property mode set to 100644
File size: 8.8 KB
Line 
1#!groovy
2
3//===========================================================================================================
4// Main loop of the compilation
5//===========================================================================================================
6node ('master'){
7
8        boolean bIsSandbox = env.BRANCH_NAME == "jenkins-sandbox"
9        def err = null
10        def log_needed = false
11
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
19
20        currentBuild.result = "SUCCESS"
21
22        try {
23                //Wrap build to add timestamp to command line
24                wrap([$class: 'TimestamperBuildWrapper']) {
25
26                        //Prevent the build from exceeding 60 minutes
27                        timeout(60) {
28
29                                notify()
30
31                                prepare_build()
32
33                                checkout()
34
35                                build()
36
37                                test()
38
39                                benchmark()
40
41                                clean()
42
43                                build_doc()
44
45                                publish()
46
47                                notify()
48                        }
49                }
50        }
51
52        //If an exception is caught we need to change the status and remember to
53        //attach the build log to the email
54        catch (Exception caughtError) {
55                //rethrow error later
56                err = caughtError
57
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()
63        }
64
65        finally {
66                echo 'Build Completed'
67
68                //Send email with final results if this is not a full build
69                if( !do_sendemail && !bIsSandbox ) {
70                        echo 'Notifying users of result'
71                        email(currentBuild.result, log_needed)
72                }
73
74                /* Must re-throw exception to propagate error */
75                if (err) {
76                        throw err
77                }
78        }
79}
80
81//===========================================================================================================
82// Helper classes/variables/routines
83//===========================================================================================================
84//Description of a compiler (Must be serializable since pipelines are persistent)
85class CC_Desc implements Serializable {
86        public String cc_name
87        public String cpp_cc
88        public String cfa_backend_cc
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        }
95}
96
97//Helper routine to collect information about the git history
98def collect_git_info() {
99
100        //create the temporary output directory in case it doesn't already exist
101        def out_dir = pwd tmp: true
102        sh "mkdir -p ${out_dir}"
103
104        //parse git logs to find what changed
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
114def prepare_build() {
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                        ],
151                ]])
152
153        compiler                = compiler_from_params()
154        architecture    = architecture_from_params()
155
156        do_alltests             = param_allTests        .toBoolean()
157        do_benchmark    = param_benchmark .toBoolean()
158        do_doc          = param_doc     .toBoolean()
159        do_publish              = param_publish         .toBoolean()
160
161        collect_git_info()
162}
163
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        }
181}
182
183//===========================================================================================================
184// Main compilation routines
185//===========================================================================================================
186//Compilation script is done here but environnement set-up and error handling is done in main loop
187def checkout() {
188        stage 'Checkout'
189                //checkout the source code and clean the repo
190                checkout scm
191
192                //Clean all temporary files to make sure no artifacts of the previous build remain
193                sh 'git clean -fdqx'
194
195                //Reset the git repo so no local changes persist
196                sh 'git reset --hard'
197}
198
199def build() {
200        stage 'Build'
201       
202                def install_dir = pwd tmp: true
203               
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
208                sh "./configure CXX=${compiler.cpp_cc} ${architecture} --with-backend-compiler=${compiler.cfa_backend_cc} --prefix=${install_dir} --enable-silent-rules --quiet"
209
210                //Compile the project
211                sh 'make -j 8 --no-print-directory V=0 install'
212}
213
214def test() {
215        stage 'Test'
216
217                //Run the tests from the tests directory
218                if ( do_alltests ) {
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                }
225}
226
227def benchmark() {
228        stage 'Benchmark'
229
230                if( !do_bencmark ) return
231
232                //Write the commit id to Benchmark
233                writeFile  file: 'bench.csv', text:'data=' + gitRefNewValue + ',' 
234 
235                //Append bench results
236                sh 'make -C src/benchmark --no-print-directory csv-data >> bench.csv'
237}
238
239def clean() {
240        stage 'Cleanup'
241
242                //do a maintainer-clean to make sure we need to remake from scratch
243                sh 'make maintainer-clean > /dev/null'
244}
245
246def build_doc() {
247        stage 'Documentation'
248
249                if( !do_doc ) return
250
251                dir ('doc/user') {
252                        make_doc()
253                }
254
255                dir ('doc/refrat') {
256                        make_doc()
257                }
258}
259
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
269//===========================================================================================================
270//Routine responsible of sending the email notification once the build is completed
271//===========================================================================================================
272//Standard build email notification
273def email(String status, boolean log) {
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
278        def gitLog = 'Error retrieving git logs'
279        def gitDiff = 'Error retrieving git diff'
280
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) {}
290
291        def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${status}] - branch ${env.BRANCH_NAME}"
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".
296
297The branch ${env.BRANCH_NAME} has been updated.
298   via  ${gitRefOldValue} (commit)
299  from  ${gitRefNewValue} (commit)
300
301Check console output at ${env.BUILD_URL} to view the results.
302
303- Status --------------------------------------------------------------
304
305BUILD# ${env.BUILD_NUMBER} - ${status}
306
307- Log -----------------------------------------------------------------
308${gitLog}
309-----------------------------------------------------------------------
310Summary of changes:
311${gitDiff}
312"""
313
314        def email_to = "pabuhr@uwaterloo.ca, rschlunt@uwaterloo.ca, a3moss@uwaterloo.ca, tdelisle@uwaterloo.ca, brice.dobry@huawei.com"
315
316        //send email notification
317        emailext body: email_body, subject: email_subject, to: email_to, attachLog: log
318}
Note: See TracBrowser for help on using the repository browser.