source: Jenkinsfile@ 2aaabbd

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

fixed stupid naming mistake in Jenkinsfile

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