-
Notifications
You must be signed in to change notification settings - Fork 143
/
Copy pathJenkinsfile
389 lines (369 loc) · 14.4 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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
/**
* This Jenkinsfile builds Theia across the major OS platforms
*/
import groovy.json.JsonSlurper
distFolder = "applications/electron/dist"
releaseBranch = "master"
// Attempt to detect that a PR is Jenkins-related, by looking-for
// the word "jenkins" (case insensitive) in PR branch name and/or
// the PR title
jenkinsRelatedRegex = "(?i).*jenkins.*"
pipeline {
agent none
options {
timeout(time: 5, unit: 'HOURS')
disableConcurrentBuilds()
}
environment {
BLUEPRINT_JENKINS_CI = 'true'
}
stages {
stage('Build') {
// only proceed when merging on the release branch or if the
// PR seems Jenkins-related
when {
anyOf {
expression {
env.JOB_BASE_NAME ==~ /$releaseBranch/
}
expression {
env.CHANGE_BRANCH ==~ /$jenkinsRelatedRegex/
}
expression {
env.CHANGE_TITLE ==~ /$jenkinsRelatedRegex/
}
}
}
parallel {
stage('Create Linux Installer') {
agent {
kubernetes {
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: theia-dev
image: eclipsetheia/theia-blueprint:builder
imagePullPolicy: Always
command:
- cat
tty: true
resources:
limits:
memory: "8Gi"
cpu: "2"
requests:
memory: "8Gi"
cpu: "2"
volumeMounts:
- name: global-cache
mountPath: /.cache
- name: global-yarn
mountPath: /.yarn
- name: global-npm
mountPath: /.npm
- name: electron-cache
mountPath: /.electron-gyp
volumes:
- name: global-cache
emptyDir: {}
- name: global-yarn
emptyDir: {}
- name: global-npm
emptyDir: {}
- name: electron-cache
emptyDir: {}
"""
}
}
steps {
container('theia-dev') {
withCredentials([string(credentialsId: "github-bot-token", variable: 'GITHUB_TOKEN')]) {
script {
buildInstaller(1200, false)
}
}
}
stash includes: "${distFolder}/*", name: 'linux'
}
post {
failure {
error("Linux installer creation failed, aborting...")
}
}
}
stage('Create Mac Installer') {
agent {
label 'macos'
}
steps {
script {
buildInstaller(60, false)
}
stash includes: "${distFolder}/*", name: 'mac'
}
post {
failure {
error("Mac installer creation failed, aborting...")
}
}
}
stage('Create Windows Installer') {
agent {
label 'windows'
}
steps {
script {
sh "npm config set msvs_version 2017"
sh "npx node-gyp install 14.20.0"
// analyze memory usage
bat "wmic ComputerSystem get TotalPhysicalMemory"
bat "wmic OS get FreePhysicalMemory"
bat "tasklist"
buildInstaller(60, true)
}
stash name: 'win'
}
post {
failure {
error("Windows installer creation failed, aborting...")
}
}
}
}
}
stage('Sign and Upload') {
// only proceed when merging on the release branch or if the
// PR seems Jenkins-related
when {
anyOf {
expression {
env.JOB_BASE_NAME ==~ /$releaseBranch/
}
expression {
env.CHANGE_BRANCH ==~ /$jenkinsRelatedRegex/
}
expression {
env.CHANGE_TITLE ==~ /$jenkinsRelatedRegex/
}
}
}
parallel {
stage('Upload Linux') {
agent any
steps {
unstash 'linux'
script {
uploadInstaller('linux')
}
}
}
stage('Sign, Notarize and Upload Mac') {
agent any
steps {
unstash 'mac'
script {
signInstaller('dmg', 'mac')
notarizeInstaller('dmg')
uploadInstaller('macos')
}
}
}
stage('Sign and Upload Windows') {
agent {
kubernetes {
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: theia-dev
image: eclipsetheia/theia-blueprint:builder
imagePullPolicy: Always
command:
- cat
tty: true
resources:
limits:
memory: "8Gi"
cpu: "2"
requests:
memory: "8Gi"
cpu: "2"
volumeMounts:
- name: global-cache
mountPath: /.cache
- name: global-yarn
mountPath: /.yarn
- name: global-npm
mountPath: /.npm
- name: electron-cache
mountPath: /.electron-gyp
- name: jnlp
volumeMounts:
- name: volume-known-hosts
mountPath: /home/jenkins/.ssh
volumes:
- name: global-cache
emptyDir: {}
- name: global-yarn
emptyDir: {}
- name: global-npm
emptyDir: {}
- name: electron-cache
emptyDir: {}
- name: volume-known-hosts
configMap:
name: known-hosts
"""
}
}
steps {
unstash 'win'
container('theia-dev') {
script {
signInstaller('exe', 'windows')
updateMetadata('TheiaBlueprint.exe', 'latest.yml', 'windows', 1200)
}
}
container('jnlp') {
script {
uploadInstaller('windows')
copyInstallerAndUpdateLatestYml('windows', 'TheiaBlueprint', 'exe', 'latest.yml', '1.36.0,1.37.0')
}
}
}
}
}
}
}
}
def buildInstaller(int sleepBetweenRetries, boolean excludeBrowser) {
int MAX_RETRY = 3
checkout scm
if (excludeBrowser) {
sh "npm install -g ts-node typescript '@types/node'"
sh "ts-node scripts/patch-workspaces.ts"
}
sh "node --version"
sh "export NODE_OPTIONS=--max_old_space_size=4096"
sh "printenv && yarn cache dir"
sh "yarn cache clean"
try {
sh(script: 'yarn --frozen-lockfile --force')
} catch(error) {
retry(MAX_RETRY) {
sleep(sleepBetweenRetries)
echo "yarn failed - Retrying"
sh(script: 'yarn --frozen-lockfile --force')
}
}
sh "rm -rf ./${distFolder}"
sshagent(['projects-storage.eclipse.org-bot-ssh']) {
sh "yarn electron deploy"
}
}
def signInstaller(String ext, String os) {
List installers = findFiles(glob: "${distFolder}/*.${ext}")
// https://wiki.eclipse.org/IT_Infrastructure_Doc#Web_service
if (os == 'mac') {
url = 'https://cbi.eclipse.org/macos/codesign/sign'
} else if (os == 'windows') {
url = 'https://cbi.eclipse.org/authenticode/sign'
} else {
error("Error during signing: unsupported OS: ${os}")
}
if (installers.size() == 1) {
sh "curl -o ${distFolder}/signed-${installers[0].name} -F file=@${installers[0].path} ${url}"
sh "rm ${installers[0].path}"
sh "mv ${distFolder}/signed-${installers[0].name} ${installers[0].path}"
} else {
error("Error during signing: installer not found or multiple installers exist: ${installers.size()}")
}
}
def notarizeInstaller(String ext) {
String service = 'https://cbi.eclipse.org/macos/xcrun'
List installers = findFiles(glob: "${distFolder}/*.${ext}")
if (installers.size() == 1) {
String response = sh(script: "curl -X POST -F file=@${installers[0].path} -F \'options={\"primaryBundleId\": \"eclipse.theia\", \"staple\": true};type=application/json\' ${service}/notarize", returnStdout: true)
def jsonSlurper = new JsonSlurper()
def json = jsonSlurper.parseText(response)
String uuid = json.uuid
while(json.notarizationStatus.status == 'IN_PROGRESS') {
sh "sleep 60"
response = sh(script: "curl ${service}/${uuid}/status", returnStdout: true)
json = jsonSlurper.parseText(response)
}
if (json.notarizationStatus.status != 'COMPLETE') {
error("Failed to notarize ${installers[0].name}: ${response}")
}
sh "curl -o ${distFolder}/stapled-${installers[0].name} ${service}/${uuid}/download"
sh "rm ${installers[0].path}"
sh "mv ${distFolder}/stapled-${installers[0].name} ${installers[0].path}"
} else {
error("Error during notarization: installer not found or multiple installers exist: ${installers.size()}")
}
}
def updateMetadata(String executable, String yaml, String platform, int sleepBetweenRetries) {
int MAX_RETRY = 4
try {
sh "export NODE_OPTIONS=--max_old_space_size=4096"
sh "yarn install --force"
sh "yarn electron update:blockmap -e ${executable}"
sh "yarn electron update:checksum -e ${executable} -y ${yaml} -p ${platform}"
} catch(error) {
retry(MAX_RETRY) {
sleep(sleepBetweenRetries)
echo "yarn failed - Retrying"
sh "yarn install --force"
sh "yarn electron update:blockmap -e ${executable}"
sh "yarn electron update:checksum -e ${executable} -y ${yaml} -p ${platform}"
}
}
}
def uploadInstaller(String platform) {
if (env.BRANCH_NAME == releaseBranch) {
def packageJSON = readJSON file: "package.json"
String version = "${packageJSON.version}"
sshagent(['projects-storage.eclipse.org-bot-ssh']) {
sh "ssh genie.theia@projects-storage.eclipse.org rm -rf /home/data/httpd/download.eclipse.org/theia/${version}/${platform}"
sh "ssh genie.theia@projects-storage.eclipse.org mkdir -p /home/data/httpd/download.eclipse.org/theia/${version}/${platform}"
sh "scp ${distFolder}/*.* genie.theia@projects-storage.eclipse.org:/home/data/httpd/download.eclipse.org/theia/${version}/${platform}"
sh "ssh genie.theia@projects-storage.eclipse.org rm -rf /home/data/httpd/download.eclipse.org/theia/latest/${platform}"
sh "ssh genie.theia@projects-storage.eclipse.org mkdir -p /home/data/httpd/download.eclipse.org/theia/latest/${platform}"
sh "scp ${distFolder}/*.* genie.theia@projects-storage.eclipse.org:/home/data/httpd/download.eclipse.org/theia/latest/${platform}"
}
} else {
echo "Skipped upload for branch ${env.BRANCH_NAME}"
}
}
/**
* Currently we have the windows updater available twice with different names.
* We want to have a name without the versions for providing a stable download link.
* Due to a bug in the nsis-updater the downloaded exe for an update needs to have a different name than initially however.
*/
def copyInstallerAndUpdateLatestYml(String platform, String installer, String extension, String yaml, String UPDATABLE_VERSIONS) {
if (env.BRANCH_NAME == releaseBranch) {
def packageJSON = readJSON file: "package.json"
String version = "${packageJSON.version}"
sshagent(['projects-storage.eclipse.org-bot-ssh']) {
sh "ssh genie.theia@projects-storage.eclipse.org cp /home/data/httpd/download.eclipse.org/theia/latest/${platform}/${installer}.${extension} /home/data/httpd/download.eclipse.org/theia/latest/${platform}/${installer}-${version}.${extension}"
sh "ssh genie.theia@projects-storage.eclipse.org cp /home/data/httpd/download.eclipse.org/theia/${version}/${platform}/${installer}.${extension} /home/data/httpd/download.eclipse.org/theia/${version}/${platform}/${installer}-${version}.${extension}"
sh "ssh genie.theia@projects-storage.eclipse.org cp /home/data/httpd/download.eclipse.org/theia/latest/${platform}/${installer}.${extension}.blockmap /home/data/httpd/download.eclipse.org/theia/latest/${platform}/${installer}-${version}.${extension}.blockmap"
sh "ssh genie.theia@projects-storage.eclipse.org cp /home/data/httpd/download.eclipse.org/theia/${version}/${platform}/${installer}.${extension}.blockmap /home/data/httpd/download.eclipse.org/theia/${version}/${platform}/${installer}-${version}.${extension}.blockmap"
}
if (UPDATABLE_VERSIONS.length() != 0) {
for (oldVersion in UPDATABLE_VERSIONS.split(",")) {
sshagent(['projects-storage.eclipse.org-bot-ssh']) {
sh "ssh genie.theia@projects-storage.eclipse.org rm -f /home/data/httpd/download.eclipse.org/theia/${oldVersion}/${platform}/${yaml}"
sh "ssh genie.theia@projects-storage.eclipse.org cp /home/data/httpd/download.eclipse.org/theia/${version}/${platform}/${yaml} /home/data/httpd/download.eclipse.org/theia/${oldVersion}/${platform}/${yaml}"
}
}
} else {
echo "No updateable versions"
}
} else {
echo "Skipped copying installer for branch ${env.BRANCH_NAME}"
}
}