source: Jenkinsfile @ ae28ee2

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 ae28ee2 was ae28ee2, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

New try at benchmark data sent to server

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