source: Jenkinsfile @ a064174

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

Fixed typo in Jenkinsfile

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