source: Jenkinsfile @ 38bfe32a

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 38bfe32a was afab6dc, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Jenkins promote - now pushes specific refs instead of simply master

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