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