source: Jenkinsfile @ 3151e3b

aaron-thesisarm-ehcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 3151e3b was 3151e3b, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

added some debug to jenkinsfile

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