forked from ghostery/browser-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile.nightly
332 lines (323 loc) · 13 KB
/
Jenkinsfile.nightly
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
#!/bin/env groovy
@Library('[email protected]') _
def matrix = [
'Cliqz ARM':[
'arch': 'arm',
'brand': 'cliqz',
'channel': 'MA02',
'target': 'arm-linux-androideabi',
],
'Cliqz X86':[
'arch': 'x86',
'brand': 'cliqz',
'channel': 'MA02',
'target': 'i686-linux-android',
],
'Ghostery ARM':[
'arch': 'arm',
'brand': 'ghostery',
'channel': 'MA52',
'target': 'arm-linux-androideabi',
],
'Ghostery X86':[
'arch': 'x86',
'brand': 'ghostery',
'channel': 'MA52',
'target': 'i686-linux-android',
],
'Bond ARM':[
'arch': 'arm',
'brand': 'bond',
'channel': 'MA62',
'target': 'arm-linux-androideabi',
],
'Bond X86':[
'arch': 'x86',
'brand': 'bond',
'channel': 'MA62',
'target': 'i686-linux-android',
],
'Cliqz Alpha':[
'arch': 'arm',
'brand': 'cliqz-alpha',
'channel': 'MA02',
'target': 'arm-linux-androideabi',
],
'Ghostery Alpha':[
'arch': 'arm',
'brand': 'ghostery-alpha',
'channel': 'MA52',
'target': 'arm-linux-androideabi',
],
]
def baseImage
def codeImage
def id
node ('master'){
def dockerTag = ""
stage('Checkout') {
checkout scm
dockerTag = readFile('mozilla-release/browser/config/version_display.txt').trim()
}
id = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
baseImageName ="browser-f/android:${dockerTag}"
codeImageName ="browser-f/android:code"
baseImage = stage('Build base image') {
docker.build(baseImageName, '--build-arg UID=`id -u` --build-arg GID=`id -g` -f Dockerfile .')
}
stage('Build code image') {
writeFile file: 'Dockerfile.code', text: """
FROM ${baseImageName}
COPY --chown=jenkins:jenkins . /app/
"""
codeImage = docker.build(
codeImageName,
'-f Dockerfile.code .',
)
}
}
def build(Map m){
def flavorname = m.name
def buildarch = m.arch
def brandname = m.brand
def cliqzchannel = m.channel
def androidtarget = m.target
def getImageName = m.getImageName
def nodeLabel = 'master'
def getId = m.getId
def apk = ""
def gradleflavor = ""
if (brandname=="bond"){
gradleflavor = "Bond"
} else {
gradleflavor = "Photon"
}
return {
node(nodeLabel){
getImageName().inside() {
stage('Download cache') {
withCredentials([
[
$class: 'UsernamePasswordMultiBinding',
credentialsId: 'f1732e5f-3e84-47ad-9286-a5fa6657ec43',
passwordVariable: 'AWS_SECRET_ACCESS_KEY',
usernameVariable: 'AWS_ACCESS_KEY_ID',
]
]) {
def s3Path = "s3://repository.cliqz.com/dist/android/cache"
def cachePath = ".gradle/caches"
sh """#!/bin/bash -l
set -e
set -x
cd
aws s3 sync --acl public-read --acl bucket-owner-full-control ${s3Path} ${cachePath}
"""
}
}
stage("Build APK: ${flavorname}") {
withEnv([
"ANDROID_TARGET=${androidtarget}",
"BRAND=${brandname}",
"CLIQZ_CHANNEL=${cliqzchannel}"
]){
sh '''#!/bin/bash -l
set -e
set -x
cd /app/mozilla-release
cp ../mozconfigs/deploy.mozconfig mozconfig
./mach clobber
./mach build
export MOZ_CHROME_MULTILOCALE=`ls -1 "../l10n/"|paste -s -d " "`
for AB_CD in $MOZ_CHROME_MULTILOCALE; do
./mach build chrome-$AB_CD
done
export AB_CD=multi
./mach package
'''
withCredentials([
file(credentialsId: 'd746a1dd-e075-4844-869a-32116a496352', variable: 'CERT_PATH' ),
string(credentialsId: 'b7422020-fe1b-4c57-9230-f3d52afee3cf', variable: 'CERT_PASS')
]) {
sh """#!/bin/bash -l
set -e
set -x
cd /app/mozilla-release
export MOZ_CHROME_MULTILOCALE=`ls -1 '../l10n/'|paste -s -d ' '`
export AB_CD=multi
./gradlew assembleOfficialWithGeckoBinariesNoMinApi${gradleflavor}Release
"""
}
apk = sh(returnStdout: true,
script: """cd /app/mozilla-release/objdir-frontend-android/${brandname}/gradle/build/mobile/android/app/outputs/apk/officialWithGeckoBinariesNoMinApi${gradleflavor}/release && \
find *.apk -name '*-release*' -not -name '*-unsigned-*'""").trim()
}
}
stage("Upload: ${flavorname}") {
withCredentials([
[
$class: 'UsernamePasswordMultiBinding',
credentialsId: 'f1732e5f-3e84-47ad-9286-a5fa6657ec43',
passwordVariable: 'AWS_SECRET_ACCESS_KEY',
usernameVariable: 'AWS_ACCESS_KEY_ID',
]
]) {
def s3Path = "s3://repository.cliqz.com/dist/android/nightly/${brandname}"
def apkPath = "/app/mozilla-release/objdir-frontend-android/${brandname}/gradle/build/mobile/android/app/outputs/apk/officialWithGeckoBinariesNoMinApi${gradleflavor}/release/${apk}"
def fileName = "${brandname}_Nightly-${env.BUILD_NUMBER}_${getId()}"
try {
zip archive: true, dir: "/app/mozilla-release/objdir-frontend-android/${brandname}/gradle/build/mobile/android/app/outputs/apk/officialWithGeckoBinariesNoMinApi${gradleflavor}/release", glob: '', zipFile: "${flavorname}-build.zip"
} catch(e) {
print e
}
if (buildarch=="arm"){
sh """#!/bin/bash -l
set -e
set -x
aws s3 cp --acl public-read --acl bucket-owner-full-control ${apkPath} ${s3Path}/${fileName}.apk
aws s3 cp --acl public-read --acl bucket-owner-full-control ${apkPath} ${s3Path}/latest.apk
"""
} else {
sh """#!/bin/bash -l
set -e
set -x
aws s3 cp --acl public-read --acl bucket-owner-full-control ${apkPath} ${s3Path}/${fileName}_${buildarch}.apk
aws s3 cp --acl public-read --acl bucket-owner-full-control ${apkPath} ${s3Path}/latest_${buildarch}.apk
"""
}
}
}
stage('Clean Up') {
sh '''#!/bin/bash
rm -f /app/mozilla-release/mozconfig
rm -rf /app/mozilla-release/objdir-frontend-android
'''
}
}
}
}
}
def stepsForParallelBuilds = helpers.entries(matrix).collectEntries{
[("Building ${it[0]}"):build(
name: it[0],
arch: it[1]['arch'],
brand: it[1]['brand'],
channel: it[1]['channel'],
target: it[1]['target'],
getImageName: {codeImage},
getId: {id}
)]
}
stage('Build Applications'){
parallel stepsForParallelBuilds
}
def transitionIssueList
stage('JIRA'){
withEnv(['JIRA_SITE=cliqztix']){
passedBuilds = []
lastSuccessfulBuild(passedBuilds,currentBuild)
def issueIds = getIssueList()
def transitionInput = [
transition: [
id: '121'
]
]
for (element in issueIds){
try{
def issue = jiraGetIssue idOrKey: element
if(issue.data.fields.status.name == "Resolved"){
jiraTransitionIssue idOrKey: element, input: transitionInput
echo "Transistioned ${element}"
} else{
echo """Element with id ${element} was not transitioned\nIts status is: """+issue.data.fields.status.name
}
}
catch (Error e){
echo e
}
}
if (issueIds.size() > 0){
transitionIssueList = issueIds.join(", ")
echo transitionIssueList
}
}
}
stage('Send email') {
def projectName = '$PROJECT_NAME'
def changesSinceLastSuccess = getChangeString(passedBuilds)
def bodytxt = """
${projectName} - Build # ${env.BUILD_NUMBER}
Check console output at ${env.JOB_URL}${env.BUILD_NUMBER}/ to view the results.
Cliqz apk Uploaded to: http://repository.cliqz.com.s3.amazonaws.com/dist/android/nightly/cliqz/cliqz_Nightly-${env.BUILD_NUMBER}_${id}.apk
Cliqz X86 apk Uploaded to: http://repository.cliqz.com.s3.amazonaws.com/dist/android/nightly/cliqz/cliqz_Nightly-${env.BUILD_NUMBER}_${id}_x86.apk
Cliqz-Alpha apk Uploaded to: http://repository.cliqz.com.s3.amazonaws.com/dist/android/nightly/cliqz-alpha/cliqz-alpha_Nightly-${env.BUILD_NUMBER}_${id}.apk
Ghostery apk Uploaded to: http://repository.cliqz.com.s3.amazonaws.com/dist/android/nightly/ghostery/ghostery_Nightly-${env.BUILD_NUMBER}_${id}.apk
Ghostery X86 apk Uploaded to: http://repository.cliqz.com.s3.amazonaws.com/dist/android/nightly/ghostery/ghostery_Nightly-${env.BUILD_NUMBER}_${id}_x86.apk
Ghostery-Alpha apk Uploaded to: http://repository.cliqz.com.s3.amazonaws.com/dist/android/nightly/ghostery-alpha/ghostery-alpha_Nightly-${env.BUILD_NUMBER}_${id}.apk
${changesSinceLastSuccess}
Issues Transtioned ${transitionIssueList}""".stripIndent()
emailext(
to: '[email protected]',
subject: '$PROJECT_NAME - Build # $BUILD_NUMBER',
body: bodytxt
)
def bodytxtBond = """
${projectName} - Build # ${env.BUILD_NUMBER}
Check console output at ${env.JOB_URL}${env.BUILD_NUMBER}/ to view the results.
Bond apk Uploaded to: http://repository.cliqz.com.s3.amazonaws.com/dist/android/nightly/bond/bond_Nightly-${env.BUILD_NUMBER}_${id}.apk
Bond X86 apk Uploaded to: http://repository.cliqz.com.s3.amazonaws.com/dist/android/nightly/bond/bond_Nightly-${env.BUILD_NUMBER}_${id}_x86.apk
${changesSinceLastSuccess}
Issues Transtioned ${transitionIssueList}""".stripIndent()
emailext(
to: '[email protected]',
subject: 'BOND » nightly - Build # $BUILD_NUMBER',
body: bodytxtBond
)
}
def lastSuccessfulBuild(passedBuilds, build) {
if ((build != null) && (build.result != 'SUCCESS')) {
echo "Finding last succesful build"
passedBuilds.add(build)
echo "Found a build"
lastSuccessfulBuild(passedBuilds, build.getPreviousBuild())
}
}
@NonCPS
def getChangeString(passedBuilds) {
def changeString = ""
echo "Gathering Changes Since Last Successful Build"
for (int x = 0; x < passedBuilds.size(); x++) {
def currentBuild = passedBuilds[x];
def buildNumber = currentBuild.number
echo "Changes for Build ${buildNumber}"
def changeLogSets = currentBuild.rawBuild.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]
changeString += "* ${entry.msg} \n"
}
}
}
if (!changeString) {
changeString = " - No new changes"
}
echo changeString
return changeString;
}
@NonCPS
def getIssueList(){
def list = []
def changes = getChangeString(passedBuilds)
def re = /AB2-([0-9])*/
def y = changes =~ re
while (y){
list.add(y.group().toString())
}
if (list.size() > 0) {
echo 'Detected JIRA tickets'
echo list.toString()
} else {
echo 'No JIRA tickets detected'
}
return list
}