1 | #!groovy |
---|
2 | |
---|
3 | //=========================================================================================================== |
---|
4 | // Main loop of the compilation |
---|
5 | //=========================================================================================================== |
---|
6 | |
---|
7 | node ('master') { |
---|
8 | def err = null |
---|
9 | |
---|
10 | try { |
---|
11 | //Wrap build to add timestamp to command line |
---|
12 | wrap([$class: 'TimestamperBuildWrapper']) { |
---|
13 | |
---|
14 | stage('Build') { |
---|
15 | |
---|
16 | results = [null, null] |
---|
17 | |
---|
18 | parallel ( |
---|
19 | gcc_6_x64: { trigger_build( 'gcc-6', 'x64', true ) }, |
---|
20 | gcc_6_x86: { trigger_build( 'gcc-6', 'x86', true ) }, |
---|
21 | gcc_5_x64: { trigger_build( 'gcc-5', 'x64', false ) }, |
---|
22 | gcc_5_x86: { trigger_build( 'gcc-5', 'x86', false ) }, |
---|
23 | gcc_4_x64: { trigger_build( 'gcc-4.9', 'x64', false ) }, |
---|
24 | gcc_4_x86: { trigger_build( 'gcc-4.9', 'x86', false ) }, |
---|
25 | clang_x64: { trigger_build( 'clang', 'x64', false ) }, |
---|
26 | clang_x86: { trigger_build( 'clang', 'x86', false ) }, |
---|
27 | ) |
---|
28 | } |
---|
29 | |
---|
30 | //Push latest changes to do-lang repo |
---|
31 | push_build() |
---|
32 | } |
---|
33 | } |
---|
34 | |
---|
35 | //If an exception is caught we need to change the status and remember to |
---|
36 | //attach the build log to the email |
---|
37 | catch (Exception caughtError) { |
---|
38 | echo('error caught') |
---|
39 | |
---|
40 | //rethrow error later |
---|
41 | err = caughtError |
---|
42 | |
---|
43 | //Store the result of the build log |
---|
44 | currentBuild.result = 'FAILURE' |
---|
45 | |
---|
46 | //Send email to notify the failure |
---|
47 | promote_failure_email() |
---|
48 | } |
---|
49 | |
---|
50 | finally { |
---|
51 | //Must re-throw exception to propagate error |
---|
52 | if (err) { |
---|
53 | throw err |
---|
54 | } |
---|
55 | } |
---|
56 | } |
---|
57 | //=========================================================================================================== |
---|
58 | // Main compilation routines |
---|
59 | //=========================================================================================================== |
---|
60 | |
---|
61 | def trigger_build(String cc, String arch, Boolean publish) { |
---|
62 | def result = build job: 'Cforall/master', \ |
---|
63 | parameters: [ \ |
---|
64 | [$class: 'StringParameterValue', \ |
---|
65 | name: 'pCompiler', \ |
---|
66 | value: cc], \ |
---|
67 | [$class: 'StringParameterValue', \ |
---|
68 | name: 'pArchitecture', \ |
---|
69 | value: arch], \ |
---|
70 | [$class: 'BooleanParameterValue', \ |
---|
71 | name: 'pRunAllTests', \ |
---|
72 | value: true], \ |
---|
73 | [$class: 'BooleanParameterValue', \ |
---|
74 | name: 'pRunBenchmark', \ |
---|
75 | value: true], \ |
---|
76 | [$class: 'BooleanParameterValue', \ |
---|
77 | name: 'pBuildDocumentation', \ |
---|
78 | value: true], \ |
---|
79 | [$class: 'BooleanParameterValue', \ |
---|
80 | name: 'pPublish', \ |
---|
81 | value: publish], \ |
---|
82 | [$class: 'BooleanParameterValue', \ |
---|
83 | name: 'pSilent', \ |
---|
84 | value: true], \ |
---|
85 | ], \ |
---|
86 | propagate: false |
---|
87 | |
---|
88 | echo(result.result) |
---|
89 | |
---|
90 | if(result.result != 'SUCCESS') { |
---|
91 | sh("wget -q -O - ${result.absoluteUrl}/consoleText") |
---|
92 | error(result.result) |
---|
93 | } |
---|
94 | } |
---|
95 | |
---|
96 | def push_build() { |
---|
97 | //Don't use the build_stage function which outputs the compiler |
---|
98 | stage('Push') { |
---|
99 | |
---|
100 | status_prefix = 'Push' |
---|
101 | |
---|
102 | def out_dir = pwd tmp: true |
---|
103 | sh "mkdir -p ${out_dir}" |
---|
104 | |
---|
105 | //checkout the code to make sure this is a valid git repo |
---|
106 | checkout scm |
---|
107 | |
---|
108 | collect_git_info() |
---|
109 | |
---|
110 | //parse git logs to find what changed |
---|
111 | sh "git remote > ${out_dir}/GIT_REMOTE" |
---|
112 | git_remote = readFile("${out_dir}/GIT_REMOTE") |
---|
113 | remoteDoLangExists = git_remote.contains("DoLang") |
---|
114 | |
---|
115 | if( !remoteDoLangExists ) { |
---|
116 | sh 'git remote add DoLang git@gitlab.do-lang.org:internal/cfa-cc.git' |
---|
117 | } |
---|
118 | |
---|
119 | //sh "GIT_SSH_COMMAND=\"ssh -v\" git push DoLang ${gitRefNewValue}:master" |
---|
120 | echo('BUILD NOT PUSH SINCE DO-LANG SERVER WAS DOWN') |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | //Helper routine to collect information about the git history |
---|
125 | def collect_git_info() { |
---|
126 | |
---|
127 | //create the temporary output directory in case it doesn't already exist |
---|
128 | def out_dir = pwd tmp: true |
---|
129 | sh "mkdir -p ${out_dir}" |
---|
130 | |
---|
131 | //parse git logs to find what changed |
---|
132 | dir("../Cforall_Full_Build@script") { |
---|
133 | sh "git reflog > ${out_dir}/GIT_COMMIT" |
---|
134 | } |
---|
135 | git_reflog = readFile("${out_dir}/GIT_COMMIT") |
---|
136 | gitRefOldValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][1] |
---|
137 | gitRefNewValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][2] |
---|
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_failure_email() { |
---|
146 | echo('notifying users') |
---|
147 | |
---|
148 | //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line |
---|
149 | //Configurations for email format |
---|
150 | def email_subject = "[cforall git][PROMOTE - FAILURE]" |
---|
151 | def email_body = """This is an automated email from the Jenkins build machine. It was |
---|
152 | generated because of a git hooks/post-receive script following |
---|
153 | a ref change was pushed to the repository containing |
---|
154 | the project "UNNAMED PROJECT". |
---|
155 | |
---|
156 | Check console output at ${env.BUILD_URL} to view the results. |
---|
157 | |
---|
158 | - Status -------------------------------------------------------------- |
---|
159 | |
---|
160 | PROMOTE FAILURE |
---|
161 | """ |
---|
162 | |
---|
163 | def email_to = "pabuhr@uwaterloo.ca, rschlunt@uwaterloo.ca, a3moss@uwaterloo.ca, tdelisle@uwaterloo.ca, brice.dobry@huawei.com, ajbeach@edu.uwaterloo.ca" |
---|
164 | |
---|
165 | //send email notification |
---|
166 | emailext body: email_body, subject: email_subject, to: email_to, attachLog: true |
---|
167 | } |
---|