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