-
-
Notifications
You must be signed in to change notification settings - Fork 356
/
Jenkinsfile
266 lines (226 loc) · 8.99 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
import hudson.tasks.test.AbstractTestResultAction
def isWindows(){
//If NODE_LABELS environment variable is null, we assume we are on master unix machine
if (env.NODE_LABELS == null) {
return false
}
return env.NODE_LABELS.toLowerCase().contains('windows')
}
// Answers if we are in a development branch (we assume is a development branch if it starts with "Pharo")
def isDevelopmentBranch() {
def branchName = env.BRANCH_NAME
def baseName = branchName.substring(0, 5)
return baseName == "Pharo"
}
// Extracts Pharo version from the development branch (if it is "Pharo7.0" it will answer "7.0")
def getPharoVersionFromBranch() {
def branchName = env.BRANCH_NAME
return branchName.substring(5)
}
def shell(params){
if(isWindows()) bat(params)
else sh(params)
}
def runTests(architecture, prefix=''){
cleanWs()
dir(env.STAGE_NAME) {
try {
unstash "bootstrap${architecture}"
shell "bash -c 'bootstrap/scripts/run${prefix}Tests.sh ${architecture} ${env.STAGE_NAME}${prefix}'"
junit allowEmptyResults: true, testResults: "${env.STAGE_NAME}${prefix}*.xml"
} finally {
archiveArtifacts allowEmptyArchive: true, artifacts: "${env.STAGE_NAME}${prefix}*.xml", fingerprint: true
archiveArtifacts allowEmptyArchive: true, artifacts: "*.fuel", fingerprint: true
// I am archiving the logs to check for crashes and errors.
if(fileExists('PharoDebug.log')){
shell "mv PharoDebug.log PharoDebug-${env.STAGE_NAME}${prefix}.log"
archiveArtifacts allowEmptyArchive: true, artifacts: "PharoDebug-${env.STAGE_NAME}${prefix}.log", fingerprint: true
}
if(fileExists('crash.dmp')){
shell "mv crash.dmp crash-${env.STAGE_NAME}${prefix}.dmp"
archiveArtifacts allowEmptyArchive: true, artifacts: "crash-${env.STAGE_NAME}${prefix}.dmp", fingerprint: true
}
if(fileExists('progress.log')){
shell "mv progress.log progress-${env.STAGE_NAME}${prefix}.log"
shell "cat progress-${env.STAGE_NAME}${prefix}.log"
archiveArtifacts allowEmptyArchive: true, artifacts: "progress-${env.STAGE_NAME}${prefix}.log", fingerprint: true
}
}
}
}
def shellOutput(params){
return (isWindows())? bat(returnStdout: true, script: params).trim() : sh(returnStdout: true, script: params).trim()
}
def notifyBuild(status){
node('unix'){ stage('notify'){
try{
//If this is development, we send the email to the beta list
def toMail = "[email protected]"
def buildKind = env.BRANCH_NAME
if (env.CHANGE_ID != null){
buildKind = "PR ${env.CHANGE_ID}"
}
if( isDevelopmentBranch() ) {
toMail = "[email protected]"
buildKind = getPharoVersionFromBranch()
}
//We checkout scm to have access to the log information
checkout scm
def owner = "pharo-project"
def title = status
//Get the merge information from the last commit
def logMessage = shellOutput('git log -1 --format="%B"')
def logSHA = shellOutput('git log -1 --format="%p"')
def mailMessage = "Could not extract further issue information from commit message: ${logMessage}"
//If there is no pull request information, we will send a log with the last commit message only
def isPRMergeCommit = logMessage.startsWith("Merge pull request ")
if (isPRMergeCommit) {
def pullRequestId = logMessage.split(' ')[3].substring(1)
def githubPullRequestHttpRequest = "https://api.github.com/repos/${owner}/pharo/pulls/${pullRequestId}"
def response = httpRequest githubPullRequestHttpRequest
if (response.status == 200) {
def pullRequestJSON = readJSON text: response.content
def pullRequestTitle = pullRequestJSON['title']
def pullRequestUrl = "https://github.com/${owner}/pharo/pull/${pullRequestId}"
mailMessage = """The Pull Request #${pullRequestId} was integrated: \"${pullRequestTitle}\"
Pull request url: ${pullRequestUrl}
"""
title = pullRequestTitle
def issueNumber = pullRequestJSON['head']['ref'].split('-')[0]
def issueUrl = "https://github.com/pharo-project/pharo/issues/${issueNumber}"
mailMessage += """
Issue Url: ${issueUrl}"""
} else {
mailMessage += """
No associated issue found"""
}
}
def body = """There is a new Pharo build available!
The status of the build #${env.BUILD_NUMBER} was: ${status}.
${mailMessage}
Build Url: ${env.BUILD_URL}
"""
mail to: toMail, cc: '[email protected]', subject: "[Pharo ${buildKind}] Build #${env.BUILD_NUMBER}: ${title}", body: body
} catch (e) {
//If there is an error during mail send, just print it and continue
echo 'Error while sending email: ' + e.toString()
} finally {
cleanWs()
}}}
}
def bootstrapImage(architectures){
cleanWs()
def builders = [:]
for (arch in architectures) {
// Need to bind the label variable before the closure - can't do 'for (label in labels)'
def architecture = arch
builders[architecture] = {
dir(architecture) {
try {
stage ("Fetch Requirements-${architecture}") {
checkout scm
// Stage 1 is to remove any artefacts, not required for Jenkins
shell "BUILD_NUMBER=${BUILD_NUMBER} BOOTSTRAP_ARCH=${architecture} bash ./bootstrap/scripts/2-download.sh"
}
stage ("Bootstrap-${architecture}") {
shell "BUILD_NUMBER=${BUILD_NUMBER} BOOTSTRAP_ARCH=${architecture} bash ./bootstrap/scripts/3-prepare.sh"
}
stage ("Full Image-${architecture}") {
shell "BUILD_NUMBER=${BUILD_NUMBER} BOOTSTRAP_ARCH=${architecture} bash ./bootstrap/scripts/4-build.sh"
stash includes: "build/bootstrap-cache/*.zip,build/bootstrap-cache/*.sources,bootstrap/scripts/**", name: "bootstrap${architecture}"
}
if( isDevelopmentBranch() ) {
stage("Upload to files.pharo.org-${architecture}") {
dir("build/bootstrap-cache") {
shell "BUILD_NUMBER=${env.BUILD_ID} bash ../../bootstrap/scripts/prepare_for_upload.sh ${architecture}"
sshagent (credentials: ['files-pharo-org-inria']) {
shell "bash ../../bootstrap/scripts/upload_to_files.pharo.org.sh"
}
}
}
}
} finally {
shell "ls -la"
if(fileExists('PharoDebug.log')){
shell "mv PharoDebug.log PharoDebug-bootstrap.log"
archiveArtifacts allowEmptyArchive: true, artifacts: "PharoDebug-bootstrap.log", fingerprint: true
}
if(fileExists('crash.dmp')){
shell "mv crash.dmp crash-bootstrap.dmp"
archiveArtifacts allowEmptyArchive: true, artifacts: "crash-bootstrap.dmp", fingerprint: true
}
archiveArtifacts artifacts: 'build/bootstrap-cache/*.zip,build/bootstrap-cache/*.sources', fingerprint: true
cleanWs()
}
}
}
}
parallel builders
}
def launchBenchmark(){
node('unix'){
stage('launchBenchmark'){
cleanWs()
projectName = env.JOB_NAME
//We checkout scm to have access to the log information
checkout scm
if (env.CHANGE_ID != null) {
//If I am in a PR the head of the repository is a merge of the base commit (the development branch) and the PR commit.
//I take the first parent of this commit. It is the commit in the PR
commit = shellOutput('git log HEAD^1 -1 --format="%H"')
isPR = true
} else {
// If it is not a PR the commit to evaluate and put the status in github is the current commit
commit = shellOutput('git log -1 --format="%H"')
isPR = false
}
build job: 'pharo-benchmarks', parameters: [text(name: 'originProjectName', value: projectName), booleanParam(name: 'isPR', value: isPR), text(name: 'commit', value: commit)], wait: false
}
}
}
try{
properties([disableConcurrentBuilds()])
// We run the whole process in 64 bits all the time.
// The 32 bits process is only run when a PR is integrated
def architectures
if(isDevelopmentBranch()){
architectures = [/*'32',*/ '64']
}else{
architectures = ['64']
}
node('unix') {
timeout(60) {
bootstrapImage(architectures)
}
}
//Testing step
def testers = [:]
def platforms = ['unix', 'osx', 'windows']
for (arch in architectures) {
// Need to bind the label variable before the closure - can't do 'for (label in labels)'
def architecture = arch
for (platf in platforms) {
// Need to bind the label variable before the closure - can't do 'for (label in labels)'
def platform = platf
// Disabling the test of 32bits
if (arch != '32') {
testers["${platform}-${architecture}"] = {
node(platform) {
stage("Tests-${platform}-${architecture}") {
timeout(35) {
runTests(architecture)
runTests(architecture, "Kernel")
}
}
}
}
}
}
}
parallel testers
notifyBuild("SUCCESS")
launchBenchmark()
} catch (e) {
notifyBuild("FAILURE")
throw e
}