[a63ad80] | 1 | #!groovy |
---|
| 2 | |
---|
[29f4fe62] | 3 | //=========================================================================================================== |
---|
[9beae23] | 4 | // Main loop of the compilation |
---|
[29f4fe62] | 5 | //=========================================================================================================== |
---|
[56a9ce6] | 6 | |
---|
[5307c33] | 7 | node('master') { |
---|
[5b8413b4] | 8 | // Globals |
---|
[bf9d323] | 9 | BuildDir = null |
---|
| 10 | SrcDir = null |
---|
[5b8413b4] | 11 | Settings = null |
---|
| 12 | StageName = '' |
---|
| 13 | |
---|
| 14 | // Local variables |
---|
[9beae23] | 15 | def err = null |
---|
| 16 | def log_needed = false |
---|
[0ef06b6] | 17 | |
---|
| 18 | currentBuild.result = "SUCCESS" |
---|
| 19 | |
---|
[9beae23] | 20 | try { |
---|
[95fdb0a] | 21 | //Wrap build to add timestamp to command line |
---|
| 22 | wrap([$class: 'TimestamperBuildWrapper']) { |
---|
[23a14d86] | 23 | |
---|
[8c700c1] | 24 | notify_server(0) |
---|
[95fdb0a] | 25 | |
---|
[c431138] | 26 | Settings = prepare_build() |
---|
[7aebc62] | 27 | |
---|
[5307c33] | 28 | node(Settings.Architecture.node) { |
---|
[bf9d323] | 29 | BuildDir = pwd tmp: true |
---|
| 30 | SrcDir = pwd tmp: false |
---|
| 31 | |
---|
[5307c33] | 32 | clean() |
---|
[0dc3ac3] | 33 | |
---|
[5307c33] | 34 | checkout() |
---|
[fde808df] | 35 | |
---|
[5307c33] | 36 | notify_server(0) |
---|
[8c700c1] | 37 | |
---|
[5307c33] | 38 | build() |
---|
[95fdb0a] | 39 | |
---|
[5307c33] | 40 | test() |
---|
[95fdb0a] | 41 | |
---|
[5307c33] | 42 | benchmark() |
---|
[95fdb0a] | 43 | |
---|
[5307c33] | 44 | build_doc() |
---|
[7359098] | 45 | |
---|
[5307c33] | 46 | publish() |
---|
| 47 | } |
---|
[9beae23] | 48 | |
---|
[65f9dec] | 49 | notify_server(45) |
---|
[9beae23] | 50 | } |
---|
[738cf8f] | 51 | } |
---|
| 52 | |
---|
[9beae23] | 53 | //If an exception is caught we need to change the status and remember to |
---|
| 54 | //attach the build log to the email |
---|
[738cf8f] | 55 | catch (Exception caughtError) { |
---|
| 56 | //rethrow error later |
---|
| 57 | err = caughtError |
---|
| 58 | |
---|
[e966ec0] | 59 | echo err.toString() |
---|
| 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 |
---|
[5b8413b4] | 65 | currentBuild.result = "${StageName} FAILURE".trim() |
---|
[738cf8f] | 66 | } |
---|
| 67 | |
---|
| 68 | finally { |
---|
[9beae23] | 69 | //Send email with final results if this is not a full build |
---|
[e966ec0] | 70 | if( Settings && !Settings.Silent ) { |
---|
[e57ebb5] | 71 | email(log_needed, Settings.IsSandbox) |
---|
[9beae23] | 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 | } |
---|
[29f4fe62] | 82 | //=========================================================================================================== |
---|
[9beae23] | 83 | // Main compilation routines |
---|
[29f4fe62] | 84 | //=========================================================================================================== |
---|
[0dc3ac3] | 85 | def clean() { |
---|
| 86 | build_stage('Cleanup') { |
---|
| 87 | // clean the build by wipping the build directory |
---|
[5b8413b4] | 88 | dir(BuildDir) { |
---|
[d4cd491] | 89 | deleteDir() |
---|
[ece8a80] | 90 | } |
---|
[620dd2b] | 91 | } |
---|
[95fdb0a] | 92 | } |
---|
[29f4fe62] | 93 | |
---|
[0dc3ac3] | 94 | //Compilation script is done here but environnement set-up and error handling is done in main loop |
---|
| 95 | def checkout() { |
---|
| 96 | build_stage('Checkout') { |
---|
| 97 | //checkout the source code and clean the repo |
---|
[a336d46] | 98 | final scmVars = checkout scm |
---|
| 99 | Settings.GitNewRef = scmVars.GIT_COMMIT |
---|
| 100 | Settings.GitOldRef = scmVars.GIT_PREVIOUS_COMMIT |
---|
[d3a4564a] | 101 | |
---|
[a336d46] | 102 | echo GitLogMessage() |
---|
[0dc3ac3] | 103 | } |
---|
| 104 | } |
---|
| 105 | |
---|
[95fdb0a] | 106 | def build() { |
---|
[620dd2b] | 107 | build_stage('Build') { |
---|
[50f2cfc] | 108 | // Build outside of the src tree to ease cleaning |
---|
[5b8413b4] | 109 | dir (BuildDir) { |
---|
[50f2cfc] | 110 | //Configure the conpilation (Output is not relevant) |
---|
| 111 | //Use the current directory as the installation target so nothing escapes the sandbox |
---|
| 112 | //Also specify the compiler by hand |
---|
[3fc5f010] | 113 | targets="" |
---|
[5afeab9] | 114 | if( Settings.RunAllTests ) { |
---|
[6bde81d] | 115 | targets="--with-target-hosts='host:debug,host:nodebug'" |
---|
[3fc5f010] | 116 | } else { |
---|
[6bde81d] | 117 | targets="--with-target-hosts='host:debug'" |
---|
[3fc5f010] | 118 | } |
---|
| 119 | |
---|
[93fe3154] | 120 | sh "${SrcDir}/configure CXX=${Settings.Compiler.CXX} CC=${Settings.Compiler.CC} ${Settings.Architecture.flags} ${targets} --quiet" |
---|
[1752d0e] | 121 | |
---|
[50f2cfc] | 122 | //Compile the project |
---|
| 123 | sh 'make -j 8 --no-print-directory' |
---|
| 124 | } |
---|
[620dd2b] | 125 | } |
---|
[95fdb0a] | 126 | } |
---|
[24eecab] | 127 | |
---|
[95fdb0a] | 128 | def test() { |
---|
[620dd2b] | 129 | build_stage('Test') { |
---|
[9e5f409] | 130 | |
---|
[5b8413b4] | 131 | dir (BuildDir) { |
---|
[0dc3ac3] | 132 | //Run the tests from the tests directory |
---|
[5afeab9] | 133 | if ( Settings.RunAllTests ) { |
---|
[b90aace] | 134 | sh 'make --no-print-directory -C tests timeouts="--timeout=600" all-tests debug=yes' |
---|
| 135 | sh 'make --no-print-directory -C tests timeouts="--timeout=600" all-tests debug=no ' |
---|
[0dc3ac3] | 136 | } |
---|
| 137 | else { |
---|
[7428ad9] | 138 | sh 'make --no-print-directory -C tests' |
---|
[0dc3ac3] | 139 | } |
---|
[9beae23] | 140 | } |
---|
[620dd2b] | 141 | } |
---|
[95fdb0a] | 142 | } |
---|
| 143 | |
---|
| 144 | def benchmark() { |
---|
[620dd2b] | 145 | build_stage('Benchmark') { |
---|
[29f4fe62] | 146 | |
---|
[5afeab9] | 147 | if( !Settings.RunBenchmark ) return |
---|
[ae28ee2] | 148 | |
---|
[5b8413b4] | 149 | dir (BuildDir) { |
---|
[0dc3ac3] | 150 | //Append bench results |
---|
[7a927ed0] | 151 | sh "make --no-print-directory -C benchmark jenkins githash=${Settings.GitNewRef} arch=${Settings.Architecture} | tee ${SrcDir}/bench.json" |
---|
[0dc3ac3] | 152 | } |
---|
[620dd2b] | 153 | } |
---|
[9beae23] | 154 | } |
---|
[efd60d67] | 155 | |
---|
[95fdb0a] | 156 | def build_doc() { |
---|
[620dd2b] | 157 | build_stage('Documentation') { |
---|
[9beae23] | 158 | |
---|
[5afeab9] | 159 | if( !Settings.BuildDocumentation ) return |
---|
[9beae23] | 160 | |
---|
| 161 | dir ('doc/user') { |
---|
| 162 | make_doc() |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | dir ('doc/refrat') { |
---|
| 166 | make_doc() |
---|
| 167 | } |
---|
[620dd2b] | 168 | } |
---|
[9beae23] | 169 | } |
---|
| 170 | |
---|
[95fdb0a] | 171 | def publish() { |
---|
[620dd2b] | 172 | build_stage('Publish') { |
---|
[95fdb0a] | 173 | |
---|
[5afeab9] | 174 | if( !Settings.Publish ) return |
---|
[95fdb0a] | 175 | |
---|
| 176 | //Then publish the results |
---|
[50f2cfc] | 177 | sh 'curl --silent --show-error -H \'Content-Type: application/json\' --data @bench.json https://cforall.uwaterloo.ca:8082/jenkins/publish > /dev/null || true' |
---|
[620dd2b] | 178 | } |
---|
[95fdb0a] | 179 | } |
---|
| 180 | |
---|
[29f4fe62] | 181 | //=========================================================================================================== |
---|
| 182 | //Routine responsible of sending the email notification once the build is completed |
---|
| 183 | //=========================================================================================================== |
---|
[a336d46] | 184 | def GitLogMessage() { |
---|
| 185 | if (!Settings || !Settings.GitOldRef || !Settings.GitNewRef) return "\nERROR retrieveing git information!\n" |
---|
[e8a22a7] | 186 | |
---|
[6e31c43] | 187 | sh "${SrcDir}/tools/PrettyGitLogs.sh ${BuildDir} ${Settings.GitOldRef} ${Settings.GitNewRef}" |
---|
| 188 | |
---|
[eda8175] | 189 | def gitUpdate = readFile("${BuildDir}/GIT_UPDATE") |
---|
| 190 | def gitLog = readFile("${BuildDir}/GIT_LOG") |
---|
| 191 | def gitDiff = readFile("${BuildDir}/GIT_DIFF") |
---|
[7a927ed0] | 192 | |
---|
[a336d46] | 193 | return """ |
---|
[848fb00] | 194 | The branch ${env.BRANCH_NAME} has been updated. |
---|
[7a927ed0] | 195 | ${gitUpdate} |
---|
[7b1a604] | 196 | |
---|
| 197 | Check console output at ${env.BUILD_URL} to view the results. |
---|
| 198 | |
---|
| 199 | - Status -------------------------------------------------------------- |
---|
| 200 | |
---|
[e57ebb5] | 201 | BUILD# ${env.BUILD_NUMBER} - ${currentBuild.result} |
---|
[e8a22a7] | 202 | |
---|
[7b1a604] | 203 | - Log ----------------------------------------------------------------- |
---|
[7a927ed0] | 204 | ${gitLog} |
---|
[7b1a604] | 205 | ----------------------------------------------------------------------- |
---|
| 206 | Summary of changes: |
---|
[7a927ed0] | 207 | ${gitDiff} |
---|
[7b1a604] | 208 | """ |
---|
[a336d46] | 209 | } |
---|
| 210 | |
---|
| 211 | //Standard build email notification |
---|
| 212 | def email(boolean log, boolean bIsSandbox) { |
---|
| 213 | //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line |
---|
| 214 | //Configurations for email format |
---|
| 215 | echo 'Notifying users of result' |
---|
| 216 | |
---|
| 217 | def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase() |
---|
| 218 | def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${currentBuild.result}] - branch ${env.BRANCH_NAME}" |
---|
| 219 | def email_body = """This is an automated email from the Jenkins build machine. It was |
---|
| 220 | generated because of a git hooks/post-receive script following |
---|
| 221 | a ref change which was pushed to the Cforall repository. |
---|
| 222 | """ + GitLogMessage() |
---|
[e8a22a7] | 223 | |
---|
[e39647e] | 224 | def email_to = "cforall@lists.uwaterloo.ca" |
---|
[e8a22a7] | 225 | |
---|
[e0549dba] | 226 | if( Settings && !Settings.IsSandbox ) { |
---|
[094a42c] | 227 | //send email notification |
---|
| 228 | emailext body: email_body, subject: email_subject, to: email_to, attachLog: log |
---|
| 229 | } else { |
---|
| 230 | echo "Would send email to: ${email_to}" |
---|
| 231 | echo "With title: ${email_subject}" |
---|
| 232 | echo "Content: \n${email_body}" |
---|
| 233 | } |
---|
[e8a22a7] | 234 | } |
---|
[5b8413b4] | 235 | |
---|
| 236 | //=========================================================================================================== |
---|
| 237 | // Helper classes/variables/routines |
---|
| 238 | //=========================================================================================================== |
---|
| 239 | //Description of a compiler (Must be serializable since pipelines are persistent) |
---|
| 240 | class CC_Desc implements Serializable { |
---|
[93fe3154] | 241 | public String name |
---|
| 242 | public String CXX |
---|
[6ebc13f] | 243 | public String CC |
---|
[93fe3154] | 244 | |
---|
[6ebc13f] | 245 | CC_Desc(String name, String CXX, String CC) { |
---|
[93fe3154] | 246 | this.name = name |
---|
| 247 | this.CXX = CXX |
---|
[6ebc13f] | 248 | this.CC = CC |
---|
[5b8413b4] | 249 | } |
---|
| 250 | } |
---|
| 251 | |
---|
| 252 | //Description of an architecture (Must be serializable since pipelines are persistent) |
---|
| 253 | class Arch_Desc implements Serializable { |
---|
| 254 | public String name |
---|
| 255 | public String flags |
---|
[5307c33] | 256 | public String node |
---|
[5b8413b4] | 257 | |
---|
[5307c33] | 258 | Arch_Desc(String name, String flags, String node) { |
---|
[5b8413b4] | 259 | this.name = name |
---|
| 260 | this.flags = flags |
---|
[5307c33] | 261 | this.node = node |
---|
[5b8413b4] | 262 | } |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | class BuildSettings implements Serializable { |
---|
| 266 | public final CC_Desc Compiler |
---|
| 267 | public final Arch_Desc Architecture |
---|
| 268 | public final Boolean RunAllTests |
---|
| 269 | public final Boolean RunBenchmark |
---|
| 270 | public final Boolean BuildDocumentation |
---|
| 271 | public final Boolean Publish |
---|
| 272 | public final Boolean Silent |
---|
| 273 | public final Boolean IsSandbox |
---|
| 274 | public final String DescLong |
---|
| 275 | public final String DescShort |
---|
| 276 | |
---|
[a336d46] | 277 | public String GitNewRef |
---|
| 278 | public String GitOldRef |
---|
| 279 | |
---|
[5b8413b4] | 280 | BuildSettings(java.util.Collections$UnmodifiableMap param, String branch) { |
---|
| 281 | switch( param.Compiler ) { |
---|
| 282 | case 'gcc-6': |
---|
| 283 | this.Compiler = new CC_Desc('gcc-6', 'g++-6', 'gcc-6') |
---|
| 284 | break |
---|
| 285 | case 'gcc-5': |
---|
| 286 | this.Compiler = new CC_Desc('gcc-5', 'g++-5', 'gcc-5') |
---|
| 287 | break |
---|
| 288 | case 'gcc-4.9': |
---|
| 289 | this.Compiler = new CC_Desc('gcc-4.9', 'g++-4.9', 'gcc-4.9') |
---|
| 290 | break |
---|
| 291 | case 'clang': |
---|
| 292 | this.Compiler = new CC_Desc('clang', 'clang++', 'gcc-6') |
---|
| 293 | break |
---|
| 294 | default : |
---|
| 295 | error "Unhandled compiler : ${cc}" |
---|
| 296 | } |
---|
| 297 | |
---|
| 298 | switch( param.Architecture ) { |
---|
| 299 | case 'x64': |
---|
[af43394] | 300 | this.Architecture = new Arch_Desc('x64', '--host=x86_64', 'master') |
---|
[5b8413b4] | 301 | break |
---|
| 302 | case 'x86': |
---|
[af43394] | 303 | this.Architecture = new Arch_Desc('x86', '--host=i386', 'master') |
---|
[5b8413b4] | 304 | break |
---|
| 305 | default : |
---|
| 306 | error "Unhandled architecture : ${arch}" |
---|
| 307 | } |
---|
| 308 | |
---|
| 309 | this.RunAllTests = param.RunAllTests |
---|
| 310 | this.RunBenchmark = param.RunBenchmark |
---|
| 311 | this.BuildDocumentation = param.BuildDocumentation |
---|
| 312 | this.Publish = param.Publish |
---|
| 313 | this.Silent = param.Silent |
---|
| 314 | this.IsSandbox = (branch == "jenkins-sandbox") |
---|
| 315 | |
---|
| 316 | def full = param.RunAllTests ? " (Full)" : "" |
---|
[93fe3154] | 317 | this.DescShort = "${ this.Compiler.name }:${ this.Architecture.name }${full}" |
---|
[5b8413b4] | 318 | |
---|
[93fe3154] | 319 | this.DescLong = """Compiler : ${ this.Compiler.name } (${ this.Compiler.CXX }/${ this.Compiler.CC }) |
---|
[5b8413b4] | 320 | Architecture : ${ this.Architecture.name } |
---|
| 321 | Arc Flags : ${ this.Architecture.flags } |
---|
| 322 | Run All Tests : ${ this.RunAllTests.toString() } |
---|
| 323 | Run Benchmark : ${ this.RunBenchmark.toString() } |
---|
| 324 | Build Documentation : ${ this.BuildDocumentation.toString() } |
---|
| 325 | Publish : ${ this.Publish.toString() } |
---|
| 326 | Silent : ${ this.Silent.toString() } |
---|
| 327 | """ |
---|
[a336d46] | 328 | |
---|
| 329 | this.GitNewRef = '' |
---|
| 330 | this.GitOldRef = '' |
---|
[5b8413b4] | 331 | } |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | def prepare_build() { |
---|
| 335 | // prepare the properties |
---|
| 336 | properties ([ \ |
---|
| 337 | [$class: 'ParametersDefinitionProperty', \ |
---|
| 338 | parameterDefinitions: [ \ |
---|
| 339 | [$class: 'ChoiceParameterDefinition', \ |
---|
| 340 | description: 'Which compiler to use', \ |
---|
| 341 | name: 'Compiler', \ |
---|
| 342 | choices: 'gcc-6\ngcc-5\ngcc-4.9\nclang', \ |
---|
| 343 | defaultValue: 'gcc-6', \ |
---|
| 344 | ], \ |
---|
| 345 | [$class: 'ChoiceParameterDefinition', \ |
---|
| 346 | description: 'The target architecture', \ |
---|
| 347 | name: 'Architecture', \ |
---|
| 348 | choices: 'x64\nx86', \ |
---|
| 349 | defaultValue: 'x64', \ |
---|
| 350 | ], \ |
---|
| 351 | [$class: 'BooleanParameterDefinition', \ |
---|
| 352 | description: 'If false, only the quick test suite is ran', \ |
---|
| 353 | name: 'RunAllTests', \ |
---|
| 354 | defaultValue: false, \ |
---|
| 355 | ], \ |
---|
| 356 | [$class: 'BooleanParameterDefinition', \ |
---|
| 357 | description: 'If true, jenkins also runs benchmarks', \ |
---|
| 358 | name: 'RunBenchmark', \ |
---|
| 359 | defaultValue: false, \ |
---|
| 360 | ], \ |
---|
| 361 | [$class: 'BooleanParameterDefinition', \ |
---|
| 362 | description: 'If true, jenkins also builds documentation', \ |
---|
| 363 | name: 'BuildDocumentation', \ |
---|
| 364 | defaultValue: true, \ |
---|
| 365 | ], \ |
---|
| 366 | [$class: 'BooleanParameterDefinition', \ |
---|
| 367 | description: 'If true, jenkins also publishes results', \ |
---|
| 368 | name: 'Publish', \ |
---|
| 369 | defaultValue: false, \ |
---|
| 370 | ], \ |
---|
| 371 | [$class: 'BooleanParameterDefinition', \ |
---|
| 372 | description: 'If true, jenkins will not send emails', \ |
---|
| 373 | name: 'Silent', \ |
---|
| 374 | defaultValue: false, \ |
---|
| 375 | ], \ |
---|
| 376 | ], |
---|
| 377 | ]]) |
---|
| 378 | |
---|
| 379 | final settings = new BuildSettings(params, env.BRANCH_NAME) |
---|
| 380 | |
---|
| 381 | currentBuild.description = settings.DescShort |
---|
| 382 | echo settings.DescLong |
---|
| 383 | |
---|
| 384 | return settings |
---|
| 385 | } |
---|
| 386 | |
---|
| 387 | def build_stage(String name, Closure block ) { |
---|
| 388 | StageName = name |
---|
| 389 | echo " -------- ${StageName} -------- " |
---|
[939fd39] | 390 | stage(name, block) |
---|
[5b8413b4] | 391 | } |
---|
| 392 | |
---|
| 393 | def notify_server(int wait) { |
---|
| 394 | sh """curl --silent --show-error --data "wait=${wait}" -X POST https://cforall.uwaterloo.ca:8082/jenkins/notify > /dev/null || true""" |
---|
| 395 | return |
---|
| 396 | } |
---|
| 397 | |
---|
| 398 | def make_doc() { |
---|
| 399 | def err = null |
---|
| 400 | try { |
---|
| 401 | sh 'make clean > /dev/null' |
---|
| 402 | sh 'make > /dev/null 2>&1' |
---|
| 403 | } |
---|
| 404 | catch (Exception caughtError) { |
---|
| 405 | err = caughtError //rethrow error later |
---|
| 406 | sh 'cat *.log' |
---|
| 407 | } |
---|
| 408 | finally { |
---|
| 409 | if (err) throw err // Must re-throw exception to propagate error |
---|
| 410 | } |
---|
| 411 | } |
---|