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