forked from cliqz-oss/browser-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile.multibranch
309 lines (271 loc) · 9.33 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
#!/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 = [
'react-native': [
'config': 'react-native.json',
],
'ghostery': [
'config': 'ghostery.js',
],
'cliqzs': [
'config': 'experiments/cliqzs.json',
],
'webextension': [
'config': 'webextension.js',
],
'cliqz-android': [
'config': 'cliqz-android.js',
'cert_credentials_id': '86407680-3a2a-42ea-9bd8-d42c0c75ed96',
'cert_pass_credentials_id': 'cae4ee4b-bb2c-4aec-99b0-040919318d87',
],
'worldcup': [
'config': 'worldcup.js',
],
/*
'anolysis': [
'config': 'experiments/anolysis.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['amo'] = [
'config': 'amo.js',
'cert_credentials_id': '766bbf53-83c2-4917-a837-ee612afcbb87',
'cert_pass_credentials_id': '9983e1f3-9c73-42e7-8036-3b34a592dd52',
]
}
def baseImage
def codeImage
def triggeringCommitHash
def version
node('master') {
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 baseImageName = 'navigation-extension/base'
def codeImageName = 'navigation-extension/code';
stage('docker build base') {
ansiColor('xterm') {
baseImage = 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
"""
codeImage = docker.build(
codeImageName,
'-f Dockerfile.code .',
)
}
stage('get version') {
codeImage.inside() {
def environment = isIntegrationBranch ? 'development' : 'production'
version = sh(returnStdout: true, script: "/app/fern.js version --environment ${environment}").trim()
}
}
}
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 getImage = m.getImage
def getCommitId = m.getCommitId
def getVersion = m.getVersion
def getIsIntegrationBranch = m.getIsIntegrationBranch
return {
node('master') {
getImage().inside() {
def isIntegrationBranch = getIsIntegrationBranch();
withEnv([
"CLIQZ_BETA=${isIntegrationBranch ? 'True' : 'False'}",
"CLIQZ_PRE_RELEASE=${isIntegrationBranch ? 'False' : 'True'}",
"CLIQZ_CHANNEL=${channel}",
"CLIQZ_CONFIG_PATH=./configs/${config}",
"GIT_COMMIT=${getCommitId()}",
"VERSION=${getVersion()}",
]) {
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',
),
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 = output.split('\n')
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'],
getImage: { codeImage },
getCommitId: { triggeringCommitHash },
getVersion: { version },
getIsIntegrationBranch: { isIntegrationBranch },
)]
}
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,
)
}
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
}
}
}
}
}
stage('upload docs') {
if (isIntegrationBranch) {
node('master') {
codeImage.inside() {
sh 'cd /app && npm run doc'
withCredentials([[
$class: 'UsernamePasswordMultiBinding',
credentialsId: '06ec4a34-9d01-46df-9ff8-64c79eda8b14',
passwordVariable: 'AWS_SECRET_ACCESS_KEY',
usernameVariable: 'AWS_ACCESS_KEY_ID',
]]) {
def s3DocPath = 's3://internal.clyqz.com/docs/browser-core'
sh "cd /app/docs && aws s3 sync . $s3DocPath --delete"
}
}
}
}
}
@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
}