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 | //parse git logs to find what changed
|
---|
32 | sh "git remote > ${out_dir}/GIT_REMOTE"
|
---|
33 | git_remote = readFile("${out_dir}/GIT_REMOTE")
|
---|
34 | remoteDoLangExists = git_remote.contains("DoLang")
|
---|
35 |
|
---|
36 | if( !remoteDoLangExists ) {
|
---|
37 | sh 'git remote add DoLang git@gitlab.do-lang.org:internal/cfa-cc.git'
|
---|
38 | }
|
---|
39 |
|
---|
40 | sh "git push DoLang ${gitRefNewValue}:master"
|
---|
41 | }
|
---|
42 |
|
---|
43 | //===========================================================================================================
|
---|
44 | // Main loop of the compilation
|
---|
45 | //===========================================================================================================
|
---|
46 |
|
---|
47 | node ('master') {
|
---|
48 | try {
|
---|
49 | //Prevent the build from exceeding 30 minutes
|
---|
50 | timeout(60) {
|
---|
51 |
|
---|
52 | //Wrap build to add timestamp to command line
|
---|
53 | wrap([$class: 'TimestamperBuildWrapper']) {
|
---|
54 |
|
---|
55 | stage 'Build'
|
---|
56 |
|
---|
57 | results = [null, null]
|
---|
58 |
|
---|
59 | parallel (
|
---|
60 | x64: {
|
---|
61 | trigger_build('64-bit')
|
---|
62 | },
|
---|
63 | x32: {
|
---|
64 | trigger_build('32-bit')
|
---|
65 | }
|
---|
66 | )
|
---|
67 |
|
---|
68 | //Push latest changes to do-lang repo
|
---|
69 | push_build()
|
---|
70 | }
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | //If an exception is caught we need to change the status and remember to
|
---|
75 | //attach the build log to the email
|
---|
76 | catch (Exception caughtError) {
|
---|
77 | //rethrow error later
|
---|
78 | err = caughtError
|
---|
79 |
|
---|
80 | //Store the result of the build log
|
---|
81 | currentBuild.result = "${status_prefix} FAILURE".trim()
|
---|
82 |
|
---|
83 | //Send email to notify the failure
|
---|
84 | promote_email(currentBuild.result)
|
---|
85 | }
|
---|
86 |
|
---|
87 | finally {
|
---|
88 | //Must re-throw exception to propagate error
|
---|
89 | if (err) {
|
---|
90 | throw err
|
---|
91 | }
|
---|
92 | }
|
---|
93 | }
|
---|
94 | //===========================================================================================================
|
---|
95 | //Routine responsible of sending the email notification once the build is completed
|
---|
96 | //===========================================================================================================
|
---|
97 |
|
---|
98 | //Email notification on a full build failure
|
---|
99 | def promote_email(String status) {
|
---|
100 | //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
|
---|
101 | //Configurations for email format
|
---|
102 | def email_subject = "[cforall git][PROMOTE - FAILURE]"
|
---|
103 | def email_body = """This is an automated email from the Jenkins build machine. It was
|
---|
104 | generated because of a git hooks/post-receive script following
|
---|
105 | a ref change was pushed to the repository containing
|
---|
106 | the project "UNNAMED PROJECT".
|
---|
107 |
|
---|
108 | Check console output at ${env.BUILD_URL} to view the results.
|
---|
109 |
|
---|
110 | - Status --------------------------------------------------------------
|
---|
111 |
|
---|
112 | PROMOTE FAILURE - ${status}
|
---|
113 | """
|
---|
114 |
|
---|
115 | def email_to = "pabuhr@uwaterloo.ca, rschlunt@uwaterloo.ca, a3moss@uwaterloo.ca, tdelisle@uwaterloo.ca, brice.dobry@huawei.com"
|
---|
116 |
|
---|
117 | //send email notification
|
---|
118 | emailext body: email_body, subject: email_subject, to: email_to, attachLog: true
|
---|
119 | }
|
---|