| [ae28ee2] | 1 | #!groovy
 | 
|---|
 | 2 | 
 | 
|---|
 | 3 | //===========================================================================================================
 | 
|---|
 | 4 | // Main loop of the compilation
 | 
|---|
 | 5 | //===========================================================================================================
 | 
|---|
 | 6 | 
 | 
|---|
 | 7 | node ('master') {
 | 
|---|
 | 8 |         def err = null
 | 
|---|
 | 9 | 
 | 
|---|
| [4af1021] | 10 |         final scmVars = checkout scm
 | 
|---|
 | 11 |         final commitId = scmVars.GIT_COMMIT
 | 
|---|
| [98168b9] | 12 | 
 | 
|---|
| [ae28ee2] | 13 |         try {
 | 
|---|
| [f408e1a] | 14 |                 //Wrap build to add timestamp to command line
 | 
|---|
 | 15 |                 wrap([$class: 'TimestamperBuildWrapper']) {
 | 
|---|
 | 16 | 
 | 
|---|
 | 17 |                         stage('Build') {
 | 
|---|
 | 18 | 
 | 
|---|
 | 19 |                                 parallel (
 | 
|---|
| [e825c9d] | 20 |                                         gcc_8_x86_new: { trigger_build( 'gcc-8',   'x86', true  ) },
 | 
|---|
 | 21 |                                         gcc_7_x86_new: { trigger_build( 'gcc-7',   'x86', true  ) },
 | 
|---|
 | 22 |                                         gcc_6_x86_new: { trigger_build( 'gcc-6',   'x86', true  ) },
 | 
|---|
| [3e5d8fb5] | 23 |                                         gcc_9_x64_new: { trigger_build( 'gcc-9',   'x64', true  ) },
 | 
|---|
 | 24 |                                         gcc_8_x64_new: { trigger_build( 'gcc-8',   'x64', true  ) },
 | 
|---|
 | 25 |                                         gcc_7_x64_new: { trigger_build( 'gcc-7',   'x64', true  ) },
 | 
|---|
 | 26 |                                         gcc_6_x64_new: { trigger_build( 'gcc-6',   'x64', true  ) },
 | 
|---|
 | 27 |                                         gcc_5_x64_new: { trigger_build( 'gcc-5',   'x64', true  ) },
 | 
|---|
 | 28 |                                         clang_x64_new: { trigger_build( 'clang',   'x64', true  ) },
 | 
|---|
 | 29 |                                         clang_x64_old: { trigger_build( 'clang',   'x64', false ) },
 | 
|---|
| [f408e1a] | 30 |                                 )
 | 
|---|
| [ae28ee2] | 31 |                         }
 | 
|---|
| [8089fde] | 32 | 
 | 
|---|
 | 33 |                         stage('Package') {
 | 
|---|
| [b19fdb9] | 34 |                                 trigger_dist( commitId, currentBuild.number.toString() )
 | 
|---|
| [8089fde] | 35 |                         }
 | 
|---|
| [ae28ee2] | 36 |                 }
 | 
|---|
| [13c98a4] | 37 | 
 | 
|---|
 | 38 |                 promote_email(true)
 | 
|---|
| [ae28ee2] | 39 |         }
 | 
|---|
 | 40 | 
 | 
|---|
 | 41 |         //If an exception is caught we need to change the status and remember to
 | 
|---|
 | 42 |         //attach the build log to the email
 | 
|---|
 | 43 |         catch (Exception caughtError) {
 | 
|---|
 | 44 |                 echo('error caught')
 | 
|---|
 | 45 | 
 | 
|---|
 | 46 |                 //rethrow error later
 | 
|---|
 | 47 |                 err = caughtError
 | 
|---|
 | 48 | 
 | 
|---|
 | 49 |                 //Store the result of the build log
 | 
|---|
 | 50 |                 currentBuild.result = 'FAILURE'
 | 
|---|
 | 51 | 
 | 
|---|
 | 52 |                 //Send email to notify the failure
 | 
|---|
| [13c98a4] | 53 |                 promote_email(false)
 | 
|---|
| [ae28ee2] | 54 |         }
 | 
|---|
 | 55 | 
 | 
|---|
 | 56 |         finally {
 | 
|---|
 | 57 |                 //Must re-throw exception to propagate error
 | 
|---|
 | 58 |                 if (err) {
 | 
|---|
 | 59 |                         throw err
 | 
|---|
 | 60 |                 }
 | 
|---|
 | 61 |         }
 | 
|---|
 | 62 | }
 | 
|---|
 | 63 | //===========================================================================================================
 | 
|---|
 | 64 | // Main compilation routines
 | 
|---|
 | 65 | //===========================================================================================================
 | 
|---|
 | 66 | 
 | 
|---|
| [956910d] | 67 | def trigger_build(String cc, String arch, boolean new_ast) {
 | 
|---|
| [9eb7a532] | 68 |         // Randomly delay the builds by a random amount to avoid hitting the SC server to hard
 | 
|---|
 | 69 |         sleep(time: 5 * Math.random(), unit:"MINUTES")
 | 
|---|
 | 70 | 
 | 
|---|
 | 71 |         // Run the build
 | 
|---|
 | 72 |         // Don't propagate, it doesn't play nice with our email setup
 | 
|---|
| [ae28ee2] | 73 |         def result = build job: 'Cforall/master',               \
 | 
|---|
 | 74 |                 parameters: [                                           \
 | 
|---|
| [8fa3c7e6] | 75 |                         [$class: 'StringParameterValue',                \
 | 
|---|
| [0c1d240] | 76 |                           name: 'Compiler',                             \
 | 
|---|
| [8fa3c7e6] | 77 |                           value: cc],                                   \
 | 
|---|
 | 78 |                         [$class: 'StringParameterValue',                \
 | 
|---|
| [0c1d240] | 79 |                           name: 'Architecture',                         \
 | 
|---|
| [8fa3c7e6] | 80 |                           value: arch],                                 \
 | 
|---|
| [849de65] | 81 |                         [$class: 'BooleanParameterValue',               \
 | 
|---|
 | 82 |                           name: 'NewAST',                               \
 | 
|---|
 | 83 |                           value: new_ast],                              \
 | 
|---|
| [ae28ee2] | 84 |                         [$class: 'BooleanParameterValue',               \
 | 
|---|
| [0c1d240] | 85 |                           name: 'RunAllTests',                          \
 | 
|---|
| [8fa3c7e6] | 86 |                           value: true],                                         \
 | 
|---|
 | 87 |                         [$class: 'BooleanParameterValue',               \
 | 
|---|
| [0c1d240] | 88 |                           name: 'RunBenchmark',                         \
 | 
|---|
| [8fa3c7e6] | 89 |                           value: true],                                         \
 | 
|---|
 | 90 |                         [$class: 'BooleanParameterValue',               \
 | 
|---|
| [0c1d240] | 91 |                           name: 'BuildDocumentation',           \
 | 
|---|
| [8fa3c7e6] | 92 |                           value: true],                                         \
 | 
|---|
 | 93 |                         [$class: 'BooleanParameterValue',               \
 | 
|---|
| [0c1d240] | 94 |                           name: 'Publish',                              \
 | 
|---|
| [849de65] | 95 |                           value: true],                                         \
 | 
|---|
| [8fa3c7e6] | 96 |                         [$class: 'BooleanParameterValue',               \
 | 
|---|
| [0c1d240] | 97 |                           name: 'Silent',                               \
 | 
|---|
| [ae28ee2] | 98 |                           value: true],                                         \
 | 
|---|
 | 99 |                 ],                                                              \
 | 
|---|
 | 100 |                 propagate: false
 | 
|---|
 | 101 | 
 | 
|---|
 | 102 |         echo(result.result)
 | 
|---|
 | 103 | 
 | 
|---|
 | 104 |         if(result.result != 'SUCCESS') {
 | 
|---|
| [27474a7] | 105 |                 sh("wget -q -O - http://localhost:8084/jenkins/job/Cforall/job/master/${result.number}/consoleText")
 | 
|---|
| [ae28ee2] | 106 |                 error(result.result)
 | 
|---|
 | 107 |         }
 | 
|---|
 | 108 | }
 | 
|---|
 | 109 | 
 | 
|---|
| [6ae5c22] | 110 | def trigger_dist(String commitId, String buildNum) {
 | 
|---|
| [b19fdb9] | 111 |         def result = build job: 'Cforall_Distribute_Ref',       \
 | 
|---|
 | 112 |                 parameters: [                                           \
 | 
|---|
 | 113 |                         string(name: 'GitRef', value: commitId),        \
 | 
|---|
| [6ae5c22] | 114 |                         string(name: 'Build' , value: buildNum) \
 | 
|---|
| [587a608] | 115 |                 ],                                                              \
 | 
|---|
 | 116 |                 propagate: false
 | 
|---|
| [b19fdb9] | 117 | 
 | 
|---|
 | 118 |         echo(result.result)
 | 
|---|
 | 119 | 
 | 
|---|
 | 120 |         if(result.result != 'SUCCESS') {
 | 
|---|
 | 121 |                 sh("wget -q -O - https://cforall.uwaterloo.ca/jenkins/job/Cforall_Distribute_Ref/${result.number}/consoleText")
 | 
|---|
 | 122 |                 error(result.result)
 | 
|---|
 | 123 |         }
 | 
|---|
 | 124 | }
 | 
|---|
 | 125 | 
 | 
|---|
| [ae28ee2] | 126 | //===========================================================================================================
 | 
|---|
 | 127 | //Routine responsible of sending the email notification once the build is completed
 | 
|---|
 | 128 | //===========================================================================================================
 | 
|---|
 | 129 | 
 | 
|---|
 | 130 | //Email notification on a full build failure
 | 
|---|
| [13c98a4] | 131 | def promote_email(boolean success) {
 | 
|---|
| [ae28ee2] | 132 |         echo('notifying users')
 | 
|---|
 | 133 | 
 | 
|---|
| [13c98a4] | 134 |         def result = success ? "PROMOTE - SUCCESS" : "PROMOTE - FAILURE"
 | 
|---|
 | 135 | 
 | 
|---|
| [ae28ee2] | 136 |         //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
 | 
|---|
 | 137 |         //Configurations for email format
 | 
|---|
| [13c98a4] | 138 |         def email_subject = "[cforall git][${result}]"
 | 
|---|
 | 139 |         def email_body = """<p>This is an automated email from the Jenkins build machine. It was
 | 
|---|
| [986e260] | 140 | generated following the result of the C\u2200 nightly build.</p>
 | 
|---|
| [13c98a4] | 141 | 
 | 
|---|
 | 142 | <p>Check console output at ${env.BUILD_URL} to view the results.</p>
 | 
|---|
 | 143 | 
 | 
|---|
 | 144 | <p>- Status --------------------------------------------------------------</p>
 | 
|---|
| [ae28ee2] | 145 | 
 | 
|---|
| [13c98a4] | 146 | <p>${result}</p>
 | 
|---|
| [ae28ee2] | 147 | 
 | 
|---|
| [b7b573c] | 148 | <p>- Performance ---------------------------------------------------------</p>
 | 
|---|
| [ae28ee2] | 149 | 
 | 
|---|
| [38c0fe5] | 150 | <img src="https://cforall.uwaterloo.ca/jenkins/job/Cforall/job/master/plot/Compilation/getPlot?index=0" >
 | 
|---|
| [a74554af] | 151 | <img src="https://cforall.uwaterloo.ca/jenkins/job/Cforall/job/master/plot/Compilation/getPlot?index=1" >
 | 
|---|
| [b7b573c] | 152 | 
 | 
|---|
 | 153 | <p>- Logs ----------------------------------------------------------------</p>
 | 
|---|
| [ae28ee2] | 154 | """
 | 
|---|
 | 155 | 
 | 
|---|
| [e39647e] | 156 |         def email_to = "cforall@lists.uwaterloo.ca"
 | 
|---|
| [ae28ee2] | 157 | 
 | 
|---|
 | 158 |         //send email notification
 | 
|---|
| [13c98a4] | 159 |         emailext body: email_body, subject: email_subject, to: email_to, attachLog: !success
 | 
|---|
| [ae28ee2] | 160 | }
 | 
|---|