[a63ad80] | 1 | #!groovy
|
---|
| 2 |
|
---|
[29f4fe62] | 3 | //===========================================================================================================
|
---|
[9beae23] | 4 | // Main loop of the compilation
|
---|
[29f4fe62] | 5 | //===========================================================================================================
|
---|
[9beae23] | 6 | node ('master'){
|
---|
[56a9ce6] | 7 |
|
---|
[9beae23] | 8 | boolean bIsSandbox = env.BRANCH_NAME == "jenkins-sandbox"
|
---|
| 9 | def err = null
|
---|
| 10 | def log_needed = false
|
---|
[0ef06b6] | 11 |
|
---|
[734891d] | 12 | stage_name = ''
|
---|
| 13 |
|
---|
[bd34bcf5] | 14 | compiler = null
|
---|
| 15 | architecture = ''
|
---|
[95fdb0a] | 16 |
|
---|
[bd34bcf5] | 17 | do_alltests = false
|
---|
| 18 | do_benchmark = false
|
---|
| 19 | do_doc = false
|
---|
| 20 | do_publish = false
|
---|
[3f09a70] | 21 | do_sendemail = true
|
---|
[56a9ce6] | 22 |
|
---|
[0ef06b6] | 23 | currentBuild.result = "SUCCESS"
|
---|
| 24 |
|
---|
[9beae23] | 25 | try {
|
---|
[95fdb0a] | 26 | //Wrap build to add timestamp to command line
|
---|
| 27 | wrap([$class: 'TimestamperBuildWrapper']) {
|
---|
[23a14d86] | 28 |
|
---|
[95fdb0a] | 29 | //Prevent the build from exceeding 60 minutes
|
---|
| 30 | timeout(60) {
|
---|
| 31 |
|
---|
[7223c671] | 32 | notify_server()
|
---|
[7aebc62] | 33 |
|
---|
[0ef06b6] | 34 | prepare_build()
|
---|
[fde808df] | 35 |
|
---|
[95fdb0a] | 36 | checkout()
|
---|
| 37 |
|
---|
| 38 | build()
|
---|
| 39 |
|
---|
| 40 | test()
|
---|
| 41 |
|
---|
| 42 | benchmark()
|
---|
[7359098] | 43 |
|
---|
[95fdb0a] | 44 | clean()
|
---|
[7359098] | 45 |
|
---|
[95fdb0a] | 46 | build_doc()
|
---|
[9beae23] | 47 |
|
---|
[95fdb0a] | 48 | publish()
|
---|
| 49 |
|
---|
[7223c671] | 50 | notify_server()
|
---|
[9beae23] | 51 | }
|
---|
| 52 | }
|
---|
[738cf8f] | 53 | }
|
---|
| 54 |
|
---|
[9beae23] | 55 | //If an exception is caught we need to change the status and remember to
|
---|
| 56 | //attach the build log to the email
|
---|
[738cf8f] | 57 | catch (Exception caughtError) {
|
---|
| 58 | //rethrow error later
|
---|
| 59 | err = caughtError
|
---|
| 60 |
|
---|
[9beae23] | 61 | //An error has occured, the build log is relevent
|
---|
| 62 | log_needed = true
|
---|
| 63 |
|
---|
| 64 | //Store the result of the build log
|
---|
[734891d] | 65 | currentBuild.result = "${stage_name} FAILURE".trim()
|
---|
[738cf8f] | 66 | }
|
---|
| 67 |
|
---|
| 68 | finally {
|
---|
[9beae23] | 69 | //Send email with final results if this is not a full build
|
---|
[14ce3392] | 70 | if( do_sendemail && !bIsSandbox ) {
|
---|
[9beae23] | 71 | echo 'Notifying users of result'
|
---|
| 72 | email(currentBuild.result, log_needed)
|
---|
| 73 | }
|
---|
| 74 |
|
---|
[734891d] | 75 | echo 'Build Completed'
|
---|
| 76 |
|
---|
[738cf8f] | 77 | /* Must re-throw exception to propagate error */
|
---|
| 78 | if (err) {
|
---|
| 79 | throw err
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[29f4fe62] | 84 | //===========================================================================================================
|
---|
[95fdb0a] | 85 | // Helper classes/variables/routines
|
---|
[29f4fe62] | 86 | //===========================================================================================================
|
---|
[ab60d6d] | 87 | //Helper routine to collect information about the git history
|
---|
| 88 | def collect_git_info() {
|
---|
| 89 |
|
---|
[abc26975] | 90 | //create the temporary output directory in case it doesn't already exist
|
---|
[ab60d6d] | 91 | def out_dir = pwd tmp: true
|
---|
[abc26975] | 92 | sh "mkdir -p ${out_dir}"
|
---|
| 93 |
|
---|
| 94 | //parse git logs to find what changed
|
---|
[ab60d6d] | 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 |
|
---|
[0ef06b6] | 104 | def prepare_build() {
|
---|
[95fdb0a] | 105 | properties ([ \
|
---|
| 106 | [$class: 'ParametersDefinitionProperty', \
|
---|
| 107 | parameterDefinitions: [ \
|
---|
| 108 | [$class: 'ChoiceParameterDefinition', \
|
---|
| 109 | description: 'Which compiler to use', \
|
---|
[0370b9b] | 110 | name: 'pCompiler', \
|
---|
[95fdb0a] | 111 | choices: 'gcc-6\ngcc-5\ngcc-4.9\nclang', \
|
---|
| 112 | defaultValue: 'gcc-6', \
|
---|
| 113 | ], \
|
---|
| 114 | [$class: 'ChoiceParameterDefinition', \
|
---|
| 115 | description: 'The target architecture', \
|
---|
[0370b9b] | 116 | name: 'pArchitecture', \
|
---|
[8fa3c7e6] | 117 | choices: 'x64\nx86', \
|
---|
| 118 | defaultValue: 'x64', \
|
---|
[95fdb0a] | 119 | ], \
|
---|
| 120 | [$class: 'BooleanParameterDefinition', \
|
---|
| 121 | description: 'If false, only the quick test suite is ran', \
|
---|
[8fa3c7e6] | 122 | name: 'pRunAllTests', \
|
---|
[95fdb0a] | 123 | defaultValue: false, \
|
---|
| 124 | ], \
|
---|
| 125 | [$class: 'BooleanParameterDefinition', \
|
---|
| 126 | description: 'If true, jenkins also runs benchmarks', \
|
---|
[8fa3c7e6] | 127 | name: 'pRunBenchmark', \
|
---|
[26a63f0] | 128 | defaultValue: true, \
|
---|
[95fdb0a] | 129 | ], \
|
---|
| 130 | [$class: 'BooleanParameterDefinition', \
|
---|
| 131 | description: 'If true, jenkins also builds documentation', \
|
---|
[0370b9b] | 132 | name: 'pBuildDocumentation', \
|
---|
[26a63f0] | 133 | defaultValue: true, \
|
---|
[95fdb0a] | 134 | ], \
|
---|
| 135 | [$class: 'BooleanParameterDefinition', \
|
---|
| 136 | description: 'If true, jenkins also publishes results', \
|
---|
[0370b9b] | 137 | name: 'pPublish', \
|
---|
[26a63f0] | 138 | defaultValue: true, \
|
---|
[fd6d74e] | 139 | ], \
|
---|
| 140 | [$class: 'BooleanParameterDefinition', \
|
---|
| 141 | description: 'If true, jenkins will not send emails', \
|
---|
[0370b9b] | 142 | name: 'pSilent', \
|
---|
[95fdb0a] | 143 | defaultValue: false, \
|
---|
| 144 | ], \
|
---|
| 145 | ],
|
---|
[0ef06b6] | 146 | ]])
|
---|
| 147 |
|
---|
[0370b9b] | 148 | compiler = compiler_from_params( pCompiler )
|
---|
| 149 | architecture = architecture_from_params( pArchitecture )
|
---|
[0ef06b6] | 150 |
|
---|
[e6b862d] | 151 | do_alltests = (pRunAllTests == 'true')
|
---|
| 152 | do_benchmark = (pRunBenchmark == 'true')
|
---|
| 153 | do_doc = (pBuildDocumentation == 'true')
|
---|
| 154 | do_publish = (pPublish == 'true')
|
---|
| 155 | do_sendemail = ! (pSilent == 'true')
|
---|
[0ef06b6] | 156 |
|
---|
[26a63f0] | 157 | echo """Compiler : ${compiler.cc_name} (${compiler.cpp_cc}/${compiler.cfa_cc})
|
---|
[6802a5f] | 158 | Architecture : ${architecture}
|
---|
[38eef0e] | 159 | Run All Tests : ${ pRunAllTests.toString() }
|
---|
| 160 | Run Benchmark : ${ pRunBenchmark.toString() }
|
---|
| 161 | Build Documentation : ${ pBuildDocumentation.toString() }
|
---|
[26a63f0] | 162 | Publish : ${ pPublish.toString() }
|
---|
[38eef0e] | 163 | Silent : ${ pSilent.toString() }
|
---|
[6802a5f] | 164 | """
|
---|
| 165 |
|
---|
[0ef06b6] | 166 | collect_git_info()
|
---|
[95fdb0a] | 167 | }
|
---|
[0ef06b6] | 168 |
|
---|
[734891d] | 169 | def build_stage(String name) {
|
---|
| 170 | stage_name = name
|
---|
| 171 | stage name
|
---|
| 172 | }
|
---|
| 173 |
|
---|
[7223c671] | 174 | def notify_server() {
|
---|
[ef9cc56] | 175 | sh 'curl --silent -X POST http://plg2:8082/jenkins/notify > /dev/null || true'
|
---|
[ed50f0ba] | 176 | return
|
---|
[95fdb0a] | 177 | }
|
---|
| 178 |
|
---|
| 179 | def make_doc() {
|
---|
| 180 | def err = null
|
---|
| 181 | try {
|
---|
| 182 | sh 'make clean > /dev/null'
|
---|
| 183 | sh 'make > /dev/null 2>&1'
|
---|
| 184 | }
|
---|
| 185 | catch (Exception caughtError) {
|
---|
| 186 | err = caughtError //rethrow error later
|
---|
| 187 | sh 'cat *.log'
|
---|
| 188 | }
|
---|
| 189 | finally {
|
---|
| 190 | if (err) throw err // Must re-throw exception to propagate error
|
---|
[bd34bcf5] | 191 | }
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | //Description of a compiler (Must be serializable since pipelines are persistent)
|
---|
| 195 | class CC_Desc implements Serializable {
|
---|
| 196 | public String cc_name
|
---|
| 197 | public String cpp_cc
|
---|
[6802a5f] | 198 | public String cfa_cc
|
---|
[bd34bcf5] | 199 |
|
---|
[6802a5f] | 200 | CC_Desc(String cc_name, String cpp_cc, String cfa_cc) {
|
---|
[bd34bcf5] | 201 | this.cc_name = cc_name
|
---|
| 202 | this.cpp_cc = cpp_cc
|
---|
[6802a5f] | 203 | this.cfa_cc = cfa_cc
|
---|
[bd34bcf5] | 204 | }
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | def compiler_from_params(cc) {
|
---|
| 208 | switch( cc ) {
|
---|
| 209 | case 'gcc-6':
|
---|
| 210 | return new CC_Desc('gcc-6', 'g++-6', 'gcc-6')
|
---|
| 211 | break
|
---|
| 212 | case 'gcc-5':
|
---|
| 213 | return new CC_Desc('gcc-5', 'g++-5', 'gcc-5')
|
---|
| 214 | break
|
---|
| 215 | case 'gcc-4.9':
|
---|
| 216 | return new CC_Desc('gcc-4.9', 'g++-4.9', 'gcc-4.9')
|
---|
| 217 | break
|
---|
| 218 | case 'clang':
|
---|
[6802a5f] | 219 | return new CC_Desc('clang', 'clang++', 'gcc-6')
|
---|
[bd34bcf5] | 220 | break
|
---|
[1e6a463] | 221 | default :
|
---|
[201d77a] | 222 | error "Unhandled compiler : ${cc}"
|
---|
[bd34bcf5] | 223 | }
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | def architecture_from_params( arch ) {
|
---|
| 227 | switch( arch ) {
|
---|
[8fa3c7e6] | 228 | case 'x64':
|
---|
[5222605] | 229 | return '--host=x86_64'
|
---|
[bd34bcf5] | 230 | break
|
---|
[8fa3c7e6] | 231 | case 'x86':
|
---|
[5222605] | 232 | return '--host=i386'
|
---|
[bd34bcf5] | 233 | break
|
---|
[1e6a463] | 234 | default :
|
---|
[201d77a] | 235 | error "Unhandled architecture : ${arch}"
|
---|
[95fdb0a] | 236 | }
|
---|
[0ef06b6] | 237 | }
|
---|
| 238 |
|
---|
[29f4fe62] | 239 | //===========================================================================================================
|
---|
[9beae23] | 240 | // Main compilation routines
|
---|
[29f4fe62] | 241 | //===========================================================================================================
|
---|
[9beae23] | 242 | //Compilation script is done here but environnement set-up and error handling is done in main loop
|
---|
[95fdb0a] | 243 | def checkout() {
|
---|
[734891d] | 244 | build_stage'Checkout'
|
---|
[9beae23] | 245 | //checkout the source code and clean the repo
|
---|
| 246 | checkout scm
|
---|
[77f347d] | 247 |
|
---|
[9beae23] | 248 | //Clean all temporary files to make sure no artifacts of the previous build remain
|
---|
| 249 | sh 'git clean -fdqx'
|
---|
[40b1df9] | 250 |
|
---|
[9beae23] | 251 | //Reset the git repo so no local changes persist
|
---|
| 252 | sh 'git reset --hard'
|
---|
[95fdb0a] | 253 | }
|
---|
[29f4fe62] | 254 |
|
---|
[95fdb0a] | 255 | def build() {
|
---|
[734891d] | 256 | build_stage'Build'
|
---|
[95fdb0a] | 257 |
|
---|
| 258 | def install_dir = pwd tmp: true
|
---|
| 259 |
|
---|
[9beae23] | 260 | //Configure the conpilation (Output is not relevant)
|
---|
| 261 | //Use the current directory as the installation target so nothing
|
---|
| 262 | //escapes the sandbox
|
---|
| 263 | //Also specify the compiler by hand
|
---|
[6802a5f] | 264 | sh "./configure CXX=${compiler.cpp_cc} ${architecture} --with-backend-compiler=${compiler.cfa_cc} --prefix=${install_dir} --enable-silent-rules --quiet"
|
---|
[9e5f409] | 265 |
|
---|
[9beae23] | 266 | //Compile the project
|
---|
| 267 | sh 'make -j 8 --no-print-directory V=0 install'
|
---|
[95fdb0a] | 268 | }
|
---|
[24eecab] | 269 |
|
---|
[95fdb0a] | 270 | def test() {
|
---|
[734891d] | 271 | build_stage'Test'
|
---|
[9e5f409] | 272 |
|
---|
[9beae23] | 273 | //Run the tests from the tests directory
|
---|
[95fdb0a] | 274 | if ( do_alltests ) {
|
---|
[9beae23] | 275 | sh 'make -C src/tests all-tests debug=yes'
|
---|
| 276 | sh 'make -C src/tests all-tests debug=no'
|
---|
| 277 | }
|
---|
| 278 | else {
|
---|
| 279 | sh 'make -C src/tests'
|
---|
| 280 | }
|
---|
[95fdb0a] | 281 | }
|
---|
| 282 |
|
---|
| 283 | def benchmark() {
|
---|
[734891d] | 284 | build_stage'Benchmark'
|
---|
[29f4fe62] | 285 |
|
---|
[6599085] | 286 | if( !do_benchmark ) return
|
---|
[ae28ee2] | 287 |
|
---|
| 288 | //Write the commit id to Benchmark
|
---|
[f9fa306] | 289 | writeFile file: 'bench.csv', text:'data=' + gitRefNewValue + ','
|
---|
[ae28ee2] | 290 |
|
---|
| 291 | //Append bench results
|
---|
[f9fa306] | 292 | sh 'make -C src/benchmark --no-print-directory csv-data >> bench.csv'
|
---|
[95fdb0a] | 293 | }
|
---|
[ae28ee2] | 294 |
|
---|
[95fdb0a] | 295 | def clean() {
|
---|
[734891d] | 296 | build_stage'Cleanup'
|
---|
[d56c05d0] | 297 |
|
---|
[9beae23] | 298 | //do a maintainer-clean to make sure we need to remake from scratch
|
---|
| 299 | sh 'make maintainer-clean > /dev/null'
|
---|
| 300 | }
|
---|
[efd60d67] | 301 |
|
---|
[95fdb0a] | 302 | def build_doc() {
|
---|
[734891d] | 303 | build_stage'Documentation'
|
---|
[9beae23] | 304 |
|
---|
[95fdb0a] | 305 | if( !do_doc ) return
|
---|
[9beae23] | 306 |
|
---|
| 307 | dir ('doc/user') {
|
---|
| 308 | make_doc()
|
---|
| 309 | }
|
---|
| 310 |
|
---|
| 311 | dir ('doc/refrat') {
|
---|
| 312 | make_doc()
|
---|
| 313 | }
|
---|
| 314 | }
|
---|
| 315 |
|
---|
[95fdb0a] | 316 | def publish() {
|
---|
[734891d] | 317 | build_stage'Publish'
|
---|
[95fdb0a] | 318 |
|
---|
| 319 | if( !do_publish ) return
|
---|
| 320 |
|
---|
| 321 | //Then publish the results
|
---|
[3f22503] | 322 | sh 'curl --silent --data @bench.csv http://plg2:8082/jenkins/publish > /dev/null || true'
|
---|
[95fdb0a] | 323 | }
|
---|
| 324 |
|
---|
[29f4fe62] | 325 | //===========================================================================================================
|
---|
| 326 | //Routine responsible of sending the email notification once the build is completed
|
---|
| 327 | //===========================================================================================================
|
---|
[a235d09] | 328 | //Standard build email notification
|
---|
[19ad15b] | 329 | def email(String status, boolean log) {
|
---|
[e8a22a7] | 330 | //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
|
---|
| 331 | //Configurations for email format
|
---|
| 332 | def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase()
|
---|
| 333 |
|
---|
[0a346e5] | 334 | def gitLog = 'Error retrieving git logs'
|
---|
| 335 | def gitDiff = 'Error retrieving git diff'
|
---|
[7b1a604] | 336 |
|
---|
[0a346e5] | 337 | try {
|
---|
| 338 |
|
---|
| 339 | sh "git rev-list --format=short ${gitRefOldValue}...${gitRefNewValue} > GIT_LOG"
|
---|
| 340 | gitLog = readFile('GIT_LOG')
|
---|
| 341 |
|
---|
| 342 | sh "git diff --stat ${gitRefNewValue} ${gitRefOldValue} > GIT_DIFF"
|
---|
| 343 | gitDiff = readFile('GIT_DIFF')
|
---|
| 344 | }
|
---|
| 345 | catch (Exception error) {}
|
---|
[7b1a604] | 346 |
|
---|
[992c26d] | 347 | def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${status}] - branch ${env.BRANCH_NAME}"
|
---|
[848fb00] | 348 | def email_body = """This is an automated email from the Jenkins build machine. It was
|
---|
| 349 | generated because of a git hooks/post-receive script following
|
---|
| 350 | a ref change was pushed to the repository containing
|
---|
| 351 | the project "UNNAMED PROJECT".
|
---|
[e8a22a7] | 352 |
|
---|
[848fb00] | 353 | The branch ${env.BRANCH_NAME} has been updated.
|
---|
[a235d09] | 354 | via ${gitRefOldValue} (commit)
|
---|
| 355 | from ${gitRefNewValue} (commit)
|
---|
[7b1a604] | 356 |
|
---|
| 357 | Check console output at ${env.BUILD_URL} to view the results.
|
---|
| 358 |
|
---|
| 359 | - Status --------------------------------------------------------------
|
---|
| 360 |
|
---|
| 361 | BUILD# ${env.BUILD_NUMBER} - ${status}
|
---|
[e8a22a7] | 362 |
|
---|
[7b1a604] | 363 | - Log -----------------------------------------------------------------
|
---|
| 364 | ${gitLog}
|
---|
| 365 | -----------------------------------------------------------------------
|
---|
| 366 | Summary of changes:
|
---|
| 367 | ${gitDiff}
|
---|
| 368 | """
|
---|
[e8a22a7] | 369 |
|
---|
[a6b7480] | 370 | def email_to = "pabuhr@uwaterloo.ca, rschlunt@uwaterloo.ca, a3moss@uwaterloo.ca, tdelisle@uwaterloo.ca, brice.dobry@huawei.com"
|
---|
[e8a22a7] | 371 |
|
---|
| 372 | //send email notification
|
---|
[1e34653] | 373 | emailext body: email_body, subject: email_subject, to: email_to, attachLog: log
|
---|
[e8a22a7] | 374 | }
|
---|