source: Jenkinsfile @ a63ad80

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

added groovy header to Jenkinsfile

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