source: Jenkinsfile@ efc15918

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 efc15918 was 545ef59, checked in by Thierry Delisle <tdelisle@…>, 9 years ago

Jenkins now uses verbose level 0 for the build

  • Property mode set to 100644
File size: 8.2 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
[371fd1b]7def cfa_build() {
[77f347d]8 build_stage 'Checkout'
[992c26d]9 def install_dir = pwd tmp: true
[77f347d]10 //checkout the source code and clean the repo
11 checkout scm
[01b8088d]12 sh 'git clean -fdqx'
13 sh 'git reset --hard'
[23a14d86]14
[77f347d]15 build_stage 'Build'
[7aebc62]16
[77f347d]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
[fd61a4f]21 sh "./configure CXX=${currentCC.cpp_cc} --with-backend-compiler=${currentCC.cfa_backend_cc} --prefix=${install_dir} --enable-silent-rules --quiet"
[fde808df]22
[77f347d]23 //Compile the project
[545ef59]24 sh 'make -j 8 V=0 install'
[fde808df]25
[77f347d]26 build_stage 'Test'
[fde808df]27
[29f4fe62]28 //Run the tests from the example directory
[fd61a4f]29 dir ('src/tests') {
[77f347d]30 sh './runTests.sh'
31 }
[fde808df]32
[77f347d]33 build_stage 'Cleanup'
[7359098]34
[86f641b]35 //do a maintainer-clean to make sure we need to remake from scratch
36 sh 'make maintainer-clean > /dev/null'
[77f347d]37}
[7359098]38
[a235d09]39def push_build() {
[1a66280]40 //Don't use the build_stage function which outputs the compiler
41 stage 'Push'
42
43 status_prefix = 'Push'
[a235d09]44
[e034675]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
[afab6dc]57 sh "git push DoLang ${gitRefNewValue}:master"
[a235d09]58}
59
[29f4fe62]60//===========================================================================================================
61// Helper classes/variables/routines to make the status and stage name easier to use
62//===========================================================================================================
[e730560]63//Description of a compiler (Must be serializable since pipelines are persistent)
64class CC_Desc implements Serializable {
[8f6b229]65 public String cc_name
66 public String cpp_cc
67 public String cfa_backend_cc
[f25bcb6]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 }
[992c26d]74}
75
[29f4fe62]76//Global Variables defining the compiler and at which point in the build we are
[aec9a67]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
[fde808df]80
[29f4fe62]81//Wrapper to sync stage name and status name
[77f347d]82def build_stage(String name) {
[8f6b229]83 def stage_name = "${currentCC.cc_name} ${name}".trim()
[77f347d]84 stage stage_name
[fde808df]85
[77f347d]86 status_prefix = stage_name
87}
[fde808df]88
[ab60d6d]89//Helper routine to collect information about the git history
90def collect_git_info() {
91
[abc26975]92 //create the temporary output directory in case it doesn't already exist
[ab60d6d]93 def out_dir = pwd tmp: true
[abc26975]94 sh "mkdir -p ${out_dir}"
95
96 //parse git logs to find what changed
[ab60d6d]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
[29f4fe62]106//===========================================================================================================
107// Main loop of the compilation
108//===========================================================================================================
[77f347d]109node ('master'){
[fde808df]110
[b8f8696]111 boolean doPromoteBuild2DoLang
[77f347d]112 def err = null
113 def log_needed = false
[ab60d6d]114 currentBuild.result = "SUCCESS"
[c7449ce2]115 status_prefix = ''
[77f347d]116
117 try {
[0207e71]118 //Prevent the build from exceeding 30 minutes
119 timeout(30) {
[40b1df9]120
[37bf576]121 //Wrap build to add timestamp to command line
122 wrap([$class: 'TimestamperBuildWrapper']) {
[29f4fe62]123
[7b1a604]124 collect_git_info()
125
[9e5f409]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)', \
[32f17dc]132 name: 'promoteBuild2DoLang' \
[9e5f409]133 ]] \
134 ]])
135
[b8f8696]136 doPromoteBuild2DoLang = promoteBuild2DoLang == 'true'
[ef77d9c]137
138 echo "FULL BUILD = ${doPromoteBuild2DoLang}"
[9e5f409]139
[29f4fe62]140 //Compile using gcc-4.9
[f979c4ab]141 currentCC = new CC_Desc('gcc-4.9', 'g++-4.9', 'gcc-4.9')
[371fd1b]142 cfa_build()
[29f4fe62]143
[40b1df9]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
[ef77d9c]152 if( doPromoteBuild2DoLang ) {
[a235d09]153 push_build()
154 }
[37bf576]155 }
[0207e71]156 }
[f43a200]157 }
158
[29f4fe62]159 //If an exception is caught we need to change the status and remember to
160 //attach the build log to the email
[fde808df]161 catch (Exception caughtError) {
[29f4fe62]162 //rethrow error later
[fde808df]163 err = caughtError
[29f4fe62]164
165 //An error has occured, the build log is relevent
[b287f67]166 log_needed = true
[29f4fe62]167
168 //Store the result of the build log
[992c26d]169 currentBuild.result = "${status_prefix} FAILURE".trim()
[fde808df]170 }
171
172 finally {
173 //Send email with final results
[1a66280]174 notify_result(doPromoteBuild2DoLang, err, currentBuild.result, log_needed)
[fde808df]175
176 /* Must re-throw exception to propagate error */
177 if (err) {
178 throw err
179 }
[d3d0069]180 }
[7aebc62]181}
[f2b977a]182
[29f4fe62]183//===========================================================================================================
184//Routine responsible of sending the email notification once the build is completed
185//===========================================================================================================
[1a66280]186def notify_result(boolean promote, Exception err, String status, boolean log) {
[a235d09]187 if(promote) {
[1a66280]188 if( err ) {
[a235d09]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
[19ad15b]221def email(String status, boolean log) {
[e8a22a7]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
[a235d09]226 sh "git rev-list --format=short ${gitRefOldValue}...${gitRefNewValue} > GIT_LOG"
[7b1a604]227 def gitLog = readFile('GIT_LOG')
228
229 sh "git diff --stat ${gitRefNewValue} ${gitRefOldValue} > GIT_DIFF"
230 def gitDiff = readFile('GIT_DIFF')
231
[992c26d]232 def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${status}] - branch ${env.BRANCH_NAME}"
[848fb00]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".
[e8a22a7]237
[848fb00]238The branch ${env.BRANCH_NAME} has been updated.
[a235d09]239 via ${gitRefOldValue} (commit)
240 from ${gitRefNewValue} (commit)
[7b1a604]241
242Check console output at ${env.BUILD_URL} to view the results.
243
244- Status --------------------------------------------------------------
245
246BUILD# ${env.BUILD_NUMBER} - ${status}
[e8a22a7]247
[7b1a604]248- Log -----------------------------------------------------------------
249${gitLog}
250-----------------------------------------------------------------------
251Summary of changes:
252${gitDiff}
253"""
[e8a22a7]254
[a6b7480]255 def email_to = "pabuhr@uwaterloo.ca, rschlunt@uwaterloo.ca, a3moss@uwaterloo.ca, tdelisle@uwaterloo.ca, brice.dobry@huawei.com"
[e8a22a7]256
257 //send email notification
[1e34653]258 emailext body: email_body, subject: email_subject, to: email_to, attachLog: log
[e8a22a7]259}
Note: See TracBrowser for help on using the repository browser.