source: Jenkinsfile @ 9beae23

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 9beae23 was 9beae23, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Cleaned Jenkinsfile to highlight main logic

  • Property mode set to 100644
File size: 8.8 KB
RevLine 
[a63ad80]1#!groovy
2
[29f4fe62]3//===========================================================================================================
[9beae23]4// Main loop of the compilation
[29f4fe62]5//===========================================================================================================
[9beae23]6node ('master'){
[56a9ce6]7
[9beae23]8        boolean bIsSandbox = env.BRANCH_NAME == "jenkins-sandbox"
9        boolean bIsFullBuild
10        def err = null
11        def log_needed = false
12        currentBuild.result = "SUCCESS"
13        status_prefix = ''
[56a9ce6]14
[9beae23]15        try {
16                //Prevent the build from exceeding 60 minutes
17                timeout(60) {
[23a14d86]18
[9beae23]19                        //Wrap build to add timestamp to command line
20                        wrap([$class: 'TimestamperBuildWrapper']) {
[7aebc62]21
[9beae23]22                                collect_git_info()
[fde808df]23
[9beae23]24                                properties ([                                                                   \
25                                        [$class: 'ParametersDefinitionProperty',                                \
26                                                parameterDefinitions: [                                         \
27                                                [$class: 'BooleanParameterDefinition',                          \
28                                                  defaultValue: false,                                          \
29                                                  description: 'If true, the build will be promoted to the do-lang git repository (on successful builds only)', \
30                                                  name: 'isFullBuild'                                   \
31                                                ],                                                              \
32                                                [$class: 'ChoiceParameterDefinition',                           \
33                                                  choices: '64-bit\n32-bit',                                    \
34                                                  defaultValue: '64-bit',                                       \
35                                                  description: 'The architecture to use for compilation',       \
36                                                  name: 'buildArchitecture'                                     \
37                                                ]]                                                              \
38                                        ]])
[fde808df]39
[9beae23]40                                bIsFullBuild = isFullBuild == 'true'
41                                architectureFlag = ''
42                                if (buildArchitecture == '64-bit') {
43                                        architectureFlag = '--host=x86_64 CXXFLAGS="-m64" CFAFLAGS="-m64"'
44                                } else if (buildArchitecture == '32-bit'){
45                                        architectureFlag = '--host=i386 CXXFLAGS="-m32" CFAFLAGS="-m32"'
46                                } else {
47                                        architectureFlag = 'ERROR'
48                                }
[fde808df]49
[9beae23]50                                echo "FULL BUILD = ${isFullBuild}\nArchitecture = ${buildArchitecture} (flag ${architectureFlag})"
[fde808df]51
[9beae23]52                                //Compile using gcc-4.9
53                                currentCC = new CC_Desc('gcc-4.9', 'g++-4.9', 'gcc-4.9')
54                                cfa_build(bIsFullBuild, architectureFlag)
[7359098]55
[9beae23]56                                //Compile latex documentation
57                                doc_build()
[7359098]58
[9beae23]59                                //Run benchmark and save result
60                                benchmark()
[738cf8f]61
[9beae23]62                                if( bIsFullBuild ) {
63                                        //Compile using gcc-5
64                                        currentCC = new CC_Desc('gcc-5', 'g++-5', 'gcc-5')
65                                        cfa_build(true, architectureFlag)
66
67                                        //Compile using gcc-4.9
68                                        currentCC = new CC_Desc('gcc-6', 'g++-6', 'gcc-6')
69                                        cfa_build(true, architectureFlag)
70                                }
71                        }
72                }
[738cf8f]73        }
74
[9beae23]75        //If an exception is caught we need to change the status and remember to
76        //attach the build log to the email
[738cf8f]77        catch (Exception caughtError) {
78                //rethrow error later
79                err = caughtError
80
[9beae23]81                //An error has occured, the build log is relevent
82                log_needed = true
83
84                //Store the result of the build log
85                currentBuild.result = "${status_prefix} FAILURE".trim()
[738cf8f]86        }
87
88        finally {
[9beae23]89                echo 'Build Completed'
90
91                //Send email with final results if this is not a full build
92                if( !bIsFullBuild && !bIsSandbox ) {
93                        echo 'Notifying users of result'
94                        email(currentBuild.result, log_needed)
95                }
96
[738cf8f]97                /* Must re-throw exception to propagate error */
98                if (err) {
99                        throw err
100                }
101        }
102}
103
[29f4fe62]104//===========================================================================================================
105// Helper classes/variables/routines to make the status and stage name easier to use
106//===========================================================================================================
[e730560]107//Description of a compiler (Must be serializable since pipelines are persistent)
108class CC_Desc implements Serializable {
[8f6b229]109        public String cc_name
110        public String cpp_cc
111        public String cfa_backend_cc
[f25bcb6]112
113        CC_Desc(String cc_name, String cpp_cc, String cfa_backend_cc) {
114                this.cc_name = cc_name
115                this.cpp_cc = cpp_cc
116                this.cfa_backend_cc = cfa_backend_cc
117        }
[992c26d]118}
119
[29f4fe62]120//Global Variables defining the compiler and at which point in the build we are
[aec9a67]121// These variables are used but can't be declared before hand because of wierd scripting rules
122// @Field String currentCC
123// @Field String status_prefix
[fde808df]124
[29f4fe62]125//Wrapper to sync stage name and status name
[77f347d]126def build_stage(String name) {
[8f6b229]127        def stage_name = "${currentCC.cc_name} ${name}".trim()
[77f347d]128        stage stage_name
[fde808df]129
[77f347d]130                status_prefix = stage_name
131}
[fde808df]132
[ab60d6d]133//Helper routine to collect information about the git history
134def collect_git_info() {
135
[abc26975]136        //create the temporary output directory in case it doesn't already exist
[ab60d6d]137        def out_dir = pwd tmp: true
[abc26975]138        sh "mkdir -p ${out_dir}"
139
140        //parse git logs to find what changed
[ab60d6d]141        gitRefName = env.BRANCH_NAME
142        dir("../${gitRefName}@script") {
143                sh "git reflog > ${out_dir}/GIT_COMMIT"
144        }
145        git_reflog = readFile("${out_dir}/GIT_COMMIT")
146        gitRefOldValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][1]
147        gitRefNewValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][2]
148}
149
[29f4fe62]150//===========================================================================================================
[9beae23]151// Main compilation routines
[29f4fe62]152//===========================================================================================================
[9beae23]153//Compilation script is done here but environnement set-up and error handling is done in main loop
154def cfa_build(boolean full_build, String flags) {
155        build_stage 'Checkout'
156                def install_dir = pwd tmp: true
157                //checkout the source code and clean the repo
158                checkout scm
[77f347d]159
[9beae23]160                //Clean all temporary files to make sure no artifacts of the previous build remain
161                sh 'git clean -fdqx'
[40b1df9]162
[9beae23]163                //Reset the git repo so no local changes persist
164                sh 'git reset --hard'
[29f4fe62]165
[9beae23]166        build_stage 'Build'
[7b1a604]167
[9beae23]168                //Configure the conpilation (Output is not relevant)
169                //Use the current directory as the installation target so nothing
170                //escapes the sandbox
171                //Also specify the compiler by hand
172                sh "./configure CXX=${currentCC.cpp_cc} ${flags} --with-backend-compiler=${currentCC.cfa_backend_cc} --prefix=${install_dir} --enable-silent-rules --quiet"
[9e5f409]173
[9beae23]174                //Compile the project
175                sh 'make -j 8 --no-print-directory V=0 install'
[24eecab]176
[9beae23]177        build_stage 'Test'
[9e5f409]178
[9beae23]179                //Run the tests from the tests directory
180                if (full_build) {
181                        sh 'make -C src/tests all-tests debug=yes'
182                        sh 'make -C src/tests all-tests debug=no'
183                }
184                else {
185                        sh 'make -C src/tests'
186                }
[29f4fe62]187
[9beae23]188        build_stage 'Cleanup'
[d56c05d0]189
[9beae23]190                //do a maintainer-clean to make sure we need to remake from scratch
191                sh 'make maintainer-clean > /dev/null'
192}
[efd60d67]193
[9beae23]194def make_doc() {
195        def err = null
[40b1df9]196
[9beae23]197        try {
198                sh 'make clean > /dev/null'
199                sh 'make > /dev/null 2>&1'
[f43a200]200        }
201
[fde808df]202        catch (Exception caughtError) {
[29f4fe62]203                //rethrow error later
[fde808df]204                err = caughtError
[29f4fe62]205
[9beae23]206                sh 'cat *.log'
[fde808df]207        }
208
209        finally {
210                /* Must re-throw exception to propagate error */
211                if (err) {
212                        throw err
213                }
[d3d0069]214        }
[7aebc62]215}
[f2b977a]216
[9beae23]217def doc_build() {
218        stage 'Documentation'
219
220                status_prefix = 'Documentation'
221
222                dir ('doc/user') {
223                        make_doc()
224                }
225
226                dir ('doc/refrat') {
227                        make_doc()
228                }
229}
230
231def benchmark() {
232        stage 'Benchmark'
233
234                status_prefix = 'Documentation'
235
236                // //We can't just write to a file outside our repo
237                // //Copy the file locally using ssh
238                // sh 'scp plg2.cs.uwaterloo.ca:/u/cforall/public_html/perf-history/concurrency.csv bench.csv'
239
240                // //Then append to the local file
241                // sh 'make -C src/benchmark csv-data >> bench.csv'
242
243                // //Then publish the file again
244                // sh 'scp bench.csv plg2.cs.uwaterloo.ca:/u/cforall/public_html/perf-history/concurrency.csv'         
245}
246
[29f4fe62]247//===========================================================================================================
248//Routine responsible of sending the email notification once the build is completed
249//===========================================================================================================
[a235d09]250//Standard build email notification
[19ad15b]251def email(String status, boolean log) {
[e8a22a7]252        //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
253        //Configurations for email format
254        def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase()
255
[0a346e5]256        def gitLog = 'Error retrieving git logs'
257        def gitDiff = 'Error retrieving git diff'
[7b1a604]258
[0a346e5]259        try {
260
261                sh "git rev-list --format=short ${gitRefOldValue}...${gitRefNewValue} > GIT_LOG"
262                gitLog = readFile('GIT_LOG')
263
264                sh "git diff --stat ${gitRefNewValue} ${gitRefOldValue} > GIT_DIFF"
265                gitDiff = readFile('GIT_DIFF')
266        }
267        catch (Exception error) {}
[7b1a604]268
[992c26d]269        def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${status}] - branch ${env.BRANCH_NAME}"
[848fb00]270        def email_body = """This is an automated email from the Jenkins build machine. It was
271generated because of a git hooks/post-receive script following
272a ref change was pushed to the repository containing
273the project "UNNAMED PROJECT".
[e8a22a7]274
[848fb00]275The branch ${env.BRANCH_NAME} has been updated.
[a235d09]276   via  ${gitRefOldValue} (commit)
277  from  ${gitRefNewValue} (commit)
[7b1a604]278
279Check console output at ${env.BUILD_URL} to view the results.
280
281- Status --------------------------------------------------------------
282
283BUILD# ${env.BUILD_NUMBER} - ${status}
[e8a22a7]284
[7b1a604]285- Log -----------------------------------------------------------------
286${gitLog}
287-----------------------------------------------------------------------
288Summary of changes:
289${gitDiff}
290"""
[e8a22a7]291
[a6b7480]292        def email_to = "pabuhr@uwaterloo.ca, rschlunt@uwaterloo.ca, a3moss@uwaterloo.ca, tdelisle@uwaterloo.ca, brice.dobry@huawei.com"
[e8a22a7]293
294        //send email notification
[1e34653]295        emailext body: email_body, subject: email_subject, to: email_to, attachLog: log
[e8a22a7]296}
Note: See TracBrowser for help on using the repository browser.