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