-
Notifications
You must be signed in to change notification settings - Fork 35
/
Jenkinsfile.multibranch
455 lines (402 loc) · 14.4 KB
/
Jenkinsfile.multibranch
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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
#!/bin/env groovy
@Library('[email protected]') _
properties([
// Allow only one job to run at a time
[$class: 'JobRestrictionProperty'],
disableConcurrentBuilds(),
])
currentBuild.description = ''
def isIntegrationBranch = env.BRANCH_NAME == 'master'
def matrix = [:]
if (env.BRANCH_NAME.startsWith('v1.')) {
matrix['browser-pre'] = [
'config': 'releases/browser.js',
]
matrix['user-agent-ios'] = [
'config': 'user-agent-ios.js',
]
}
if (env.BRANCH_NAME.startsWith('v3.')) {
matrix['cliqz-android'] = [
'config': 'cliqz-android.js',
]
matrix['ghostery-android-privacy'] = [
'config': 'ghostery-android-privacy.js',
]
matrix['ghostery-android-search'] = [
'config': 'ghostery-android-search.js',
]
matrix['lumen-ios'] = [
'config': 'lumen-ios.js',
]
matrix['user-agent-ios'] = [
'config': 'user-agent-ios.js',
]
matrix['ghostery-ios'] = [
'config': 'ghostery-ios.js',
]
}
if (env.BRANCH_NAME == 'cliqz-mobile') {
matrix['instant-search'] = [
'config': 'instant-search.js',
]
}
if (env.BRANCH_NAME.startsWith('v7.')) {
matrix['ghostery'] = [
'config': 'ghostery.js',
]
}
if (env.BRANCH_NAME.startsWith('v9.')) {
matrix['cliqz-tab'] = [
'config': 'releases/cliqz-tab-chrome.js',
]
}
if (env.BRANCH_NAME.startsWith('v10.')) {
matrix['ghostery-tab-chrome'] = [
'config': 'releases/ghostery-tab-chrome.js',
]
matrix['ghostery-tab-firefox'] = [
'config': 'releases/ghostery-tab-firefox.js',
]
}
if (env.BRANCH_NAME.startsWith('v11.')) {
matrix['offers-chrome'] = [
'config': 'releases/offers-chrome.js',
]
matrix['offers-firefox'] = [
'config': 'releases/offers-firefox.js',
]
}
if (env.BRANCH_NAME.startsWith('v12.')) {
matrix['cliqz-geckoview'] = [
'config': 'cliqz-geckoview.js',
]
}
if (env.BRANCH_NAME.startsWith('v13.')) {
matrix['lumen-ios'] = [
'config': 'lumen-ios.js',
]
}
if (env.BRANCH_NAME.startsWith('v14.')) {
matrix['offers-chip-firefox'] = [
'config': 'releases/offers-chip-firefox.js',
]
matrix['offers-chip-chrome'] = [
'config': 'releases/offers-chip-chrome.js',
]
matrix['offers-chip-edge'] = [
'config': 'releases/offers-chip-edge.js',
]
}
if (isIntegrationBranch) {
matrix['browser'] = [
'config': 'browser.js',
'cert_credentials_id': '766bbf53-83c2-4917-a837-ee612afcbb87',
'cert_pass_credentials_id': '9983e1f3-9c73-42e7-8036-3b34a592dd52',
]
// matrix['cliqz-tab-chrome-nightly'] = [
// 'config': 'cliqz-tab-chrome.js',
// ]
matrix['instant-search'] = [
'config': 'instant-search.js',
]
// matrix['cliqz-tab-firefox-nightly'] = [
// 'config': 'cliqz-tab-firefox.js',
// 'upload_api_id': '17f59394-d13b-476e-84d5-7888c9737ced',
// 'upload_api_secret': '64b879c6-90f0-4242-9da8-87e1f0cacf94',
// ]
// matrix['ghostery-tab-chrome-nightly'] = [
// 'config': 'ghostery-tab-chrome.js',
// ]
// matrix['ghostery-tab-firefox-nightly'] = [
// 'config': 'ghostery-tab-firefox.js',
// 'upload_api_id': '17f59394-d13b-476e-84d5-7888c9737ced',
// 'upload_api_secret': '64b879c6-90f0-4242-9da8-87e1f0cacf94',
// ]
matrix['offers-nightly'] = [
'config': 'offers.js',
]
matrix['user-agent-ios'] = [
'config': 'user-agent-ios.js',
]
matrix['ghostery-ios'] = [
'config': 'ghostery-ios.js',
]
matrix['ghostery'] = [
'config': 'ghostery.js',
]
matrix['cliqz-android'] = [
'config': 'cliqz-android.js',
]
matrix['ghostery-android-privacy'] = [
'config': 'ghostery-android-privacy.js',
]
matrix['ghostery-android-search'] = [
'config': 'ghostery-android-search.js',
]
matrix['cliqz-geckoview'] = [
'config': 'cliqz-geckoview.js',
]
matrix['lumen-ios'] = [
'config': 'lumen-ios.js',
]
}
def codeImageName
def triggeringCommitHash
node('master') {
try {
stage('checkout') {
checkout scm
// TODO: use return value from checkout, when pipeline plugin will be updated
triggeringCommitHash = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim()
}
stage('checkout xpi-sign') {
// TODO: this repository does not have to be private
checkout([
$class: 'GitSCM',
branches: [[name: '*/cliqz-ci']],
doGenerateSubmoduleConfigurations: false,
extensions: [[
$class: 'RelativeTargetDirectory',
relativeTargetDir: 'xpi-sign',
]],
submoduleCfg: [],
userRemoteConfigs: [[
credentialsId: '41572f9c-06aa-46f0-9c3b-b7f4f78e9caa',
url: '[email protected]:cliqz/xpi-sign.git'
]],
])
}
def dockerfileChecksum = sh(returnStdout: true, script: 'md5sum Dockerfile.publish | cut -d" " -f1').trim()
def packageJsonChecksum = sh(returnStdout: true, script: 'md5sum package.json | cut -d" " -f1').trim()
// add date to the tag in order to download FF beta and nightly at least once per day and stay up-to-date
def today = new Date().format('yyyyMMdd')
def dockerTag = "${dockerfileChecksum}-${packageJsonChecksum}-${today}"
def baseImageName = "navigation-extension/base:${dockerTag}"
codeImageName = "navigation-extension/code:${triggeringCommitHash}";
stage('docker build base') {
timeout(30) {
ansiColor('xterm') {
docker.build(
baseImageName,
'--build-arg UID=`id -u` --build-arg GID=`id -g` -f Dockerfile.publish .',
)
}
}
}
stage('docker build code') {
writeFile file: 'Dockerfile.code', text: """
FROM ${baseImageName}
USER root
ADD . /app/
RUN chown jenkins:jenkins -R /app
USER jenkins
"""
docker.build(
codeImageName,
'-f Dockerfile.code .',
)
}
}
catch (all) {
echo 'FAILURE !!!'
emailext(
to: '[email protected]',
subject: '$PROJECT_NAME - Build # $BUILD_NUMBER Failed!!!',
body: 'Build Failed \n\nCheck console output at ' + env.BUILD_URL + ' to view the cause.'
)
currentBuild.result = 'FAILURE'
throw all
}
}
def build(Map m) {
def channel = m.channel
def config = m.config
def certCredentialsId = m.certCredentialsId ? m.certCredentialsId : '766bbf53-83c2-4917-a837-ee612afcbb87'
def certPassCredentialsId = m.certPassCredentialsId ? m.certPassCredentialsId : '9983e1f3-9c73-42e7-8036-3b34a592dd52'
def uploadApiId = m.uploadApiId ? m.uploadApiId : 'aee682e7-3992-479f-b5a9-85c6ec105e5a'
def uploadApiSecret = m.uploadApiSecret ? m.uploadApiSecret : 'b35a2a5d-6b52-4e61-a7c5-dd8a78fd9108'
def getImageName = m.getImageName
def getCommitId = m.getCommitId
def getIsIntegrationBranch = m.getIsIntegrationBranch
return {
node('master') {
docker.image(getImageName()).inside() {
def isIntegrationBranch = getIsIntegrationBranch();
def version = sh(returnStdout: true, script: "cd /app && ./fern.js version ./configs/${config}").trim()
echo "version: $version"
withEnv([
"CLIQZ_BETA=${isIntegrationBranch ? 'True' : 'False'}",
"CLIQZ_PRE_RELEASE=${isIntegrationBranch ? 'False' : 'True'}",
"CLIQZ_CHANNEL=${channel}",
"CLIQZ_CONFIG_PATH=./configs/${config}",
"GIT_COMMIT=${getCommitId()}",
"VERSION=${version}",
]) {
sh "cd /app && ./fern.js build --environment=production ${isIntegrationBranch ? '' : '--no-debug'}"
sh 'cd /app && ./fern.js pack'
withCredentials([
[
$class: 'UsernamePasswordMultiBinding',
credentialsId: '06ec4a34-9d01-46df-9ff8-64c79eda8b14',
passwordVariable: 'AWS_SECRET_ACCESS_KEY',
usernameVariable: 'AWS_ACCESS_KEY_ID',
],
usernamePassword(
credentialsId: '774bccf1-ae66-41e1-9f2e-f8efb4bedc21',
passwordVariable: 'BALROG_PASSWORD',
usernameVariable: 'BALROG_ADMIN',
),
/* credentials for webstore / AMO publish */
string(
credentialsId: uploadApiId,
variable: 'UPLOAD_API_KEY',
),
string(
credentialsId: uploadApiSecret,
variable: 'UPLOAD_API_SECRET',
),
string(
credentialsId: '2ac4ba97-d033-46bb-9e78-d8ae9b069e1d',
variable: 'REFRESH_TOKEN',
),
/* end - credentials for webstore / AMO publish */
file(
credentialsId: certCredentialsId,
variable: 'CLIQZ_CERT_PATH',
),
file(
credentialsId: certPassCredentialsId,
variable: 'CLIQZ_CERT_PASS_PATH',
),
]) {
def signOutput = sh(
returnStdout: true,
script: 'cd /app && ./fern.js sign',
).trim()
echo signOutput
def output = sh(
returnStdout: true,
script: 'cd /app && ./fern.js publish',
).trim()
echo output
def urls = getUrls(output)
for (url in urls) {
currentBuild.description += "${url}\n"
}
}
}
}
}
}
}
def stepsForParallel = helpers.entries(matrix).collectEntries {
[(it[0]): build(
channel: it[0],
config: it[1]['config'],
certCredentialsId: it[1]['cert_credentials_id'],
certPassCredentialsId: it[1]['cert_pass_credentials_id'],
uploadApiId: it[1]['upload_api_id'],
uploadApiSecret: it[1]['upload_api_secret'],
getImageName: { codeImageName },
getCommitId: { triggeringCommitHash },
getIsIntegrationBranch: { isIntegrationBranch },
)]
}
try{
stage('build and publish') {
parallel stepsForParallel
}
stage('send email') {
def bodytxt = '$PROJECT_NAME - Build # $BUILD_NUMBER'
bodytxt += '\n\nCheck console output at ' + env.BUILD_URL + ' to view the results.'
bodytxt += '\n\nArtifacts:\n\n'
bodytxt += currentBuild.description
bodytxt += '\n\n\n\n\n $CHANGES_SINCE_LAST_SUCCESS'
bodytxt += '\n\n Don\' worry, be happy :-)'
emailext(
to: '[email protected]',
subject: '$PROJECT_NAME - Build # $BUILD_NUMBER',
body: bodytxt,
)
}
if (env.BRANCH_NAME.startsWith('v')) {
stage('update jira') {
if (isIntegrationBranch) {
withEnv(['JIRA_SITE=cliqztix']) {
def issueIds = getIssueList(/EX-[0-9]+/)
def transitionInput = [
transition: [
id: '121',
],
]
if (issueIds.size() > 0) {
echo 'Detected JIRA tickets'
echo issueIds.toString()
} else {
echo 'No JIRA tickets detected'
}
for (id in issueIds) {
try {
def issue = jiraGetIssue idOrKey: id
if (issue.data.fields.status.name == "Resolved") {
jiraTransitionIssue idOrKey: id, input: transitionInput
}
} catch (Error e) {
echo e
}
}
}
}
}
}
}
catch (all) {
echo 'FAILURE !!!'
emailext(
to: '[email protected]',
subject: '$PROJECT_NAME - Build # $BUILD_NUMBER Failed!!!',
body: '\n\nCheck console output at ' + env.BUILD_URL + ' to view the cause.'
)
currentBuild.result = 'FAILURE'
throw all
}
@NonCPS
def getChangeString() {
def MAX_MSG_LEN = 100
def changeString = ""
def changeLogSets = currentBuild.changeSets
for (int i = 0; i < changeLogSets.size(); i++) {
def entries = changeLogSets[i].items
for (int j = 0; j < entries.length; j++) {
def entry = entries[j]
truncated_msg = entry.msg.take(MAX_MSG_LEN)
changeString += " - ${truncated_msg} [${entry.author}]\n"
}
}
if (!changeString) {
changeString = " - No new changes"
}
return changeString
}
@NonCPS
def getIssueList(re) {
def list = []
def changes = getChangeString()
def y = changes =~ re
while (y) {
list.add(y.group().toString())
}
return list
}
@NonCPS
def getUrls(output) {
def out = []
def log = output
def y = log =~ /(^|[ \t\r\n])((s3|ftp|http|https|gopher|mailto|news|nntp|telnet|wais|file|prospero|aim|webcal):\/\/(([a-zA-Z0-9\$\/_.+!*(),;?:@&~=-])|%[A-Za-z0-9]{2}){2,}(#([a-zA-Z0-9][a-zA-Z0-9\$_.+!*(),;?:@&~=%-]*))?([A-Za-z0-9\$_+!*():?:~-]))/
while (y) {
def u = y.group().toString().trim().replaceFirst(/^s3:\/\/cdncliqz\//, 'https://s3.amazonaws.com/cdncliqz/')
out.add(u)
}
return out.sort().unique()
}