source: Jenkinsfile@ 7ef1555e

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 7ef1555e was 7ef1555e, checked in by Thierry Delisle <tdelisle@…>, 10 years ago

Jenkins now builds all tests when doing a full build

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