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