forked from ghostery/browser-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
313 lines (304 loc) · 13.3 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
#!/bin/env groovy
@Library('[email protected]') _
def matrix = [
'cliqz':[
'bundleid': 'com.cliqz.browser',
'target': 'i686-linux-android',
'test': false,
],
'ghostery':[
'bundleid': 'com.ghostery.android.ghostery',
'target': 'i686-linux-android',
'test': true,
],
'cliqz-alpha':[
'bundleid': 'com.cliqz.browser.alpha',
'target': 'arm-linux-androideabi',
'test': false,
],
'ghostery-alpha':[
'bundleid': 'com.ghostery.android.alpha',
'target': 'arm-linux-androideabi',
'test': false,
],
]
def build(Map m){
def androidtarget = m.target
def flavorname = m.name
def bundleid = m.bundleid
def nodeLabel = 'us-east-1 && ubuntu && docker && !gpu'
def test = m.test
return {
node(nodeLabel){
def dockerTag = ""
def apk = ""
setupTestInstance(
test,
"ami-07457b491395bb595",
"1",
"t2.medium",
"android_ci_genymotion",
"sg-5bbf173f",
"subnet-341ff61f",
"us-east-1"
) {
stage('Checkout') {
checkout scm
dockerTag = readFile('mozilla-release/browser/config/version_display.txt').trim()
}
def baseImageName = "browser-f/android:${dockerTag}"
docker.withRegistry('https://141047255820.dkr.ecr.us-east-1.amazonaws.com') {
docker.image("${baseImageName}").inside {
stage('Download cache') {
withCredentials([[
$class: 'AmazonWebServicesCredentialsBinding',
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
credentialsId: 'd7e38c4a-37eb-490b-b4da-2f53cc14ab1b',
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
def s3Path = "s3://repository.cliqz.com/dist/android/cache"
def cachePath = ".gradle/caches"
sh """#!/bin/bash -l
pip install awscli --upgrade --user
cd
aws s3 sync --acl public-read --acl bucket-owner-full-control ${s3Path} ${cachePath}
"""
}
}
stage("Build APK: ${flavorname}") {
withEnv([
"ANDROID_TARGET=${androidtarget}",
"BRAND=${flavorname}",
"CLIQZ_CHANNEL=MA99"
]) {
sh '''#!/bin/bash -l
set -x
set -e
cp mozconfigs/jenkins.mozconfig mozilla-release/mozconfig
cd mozilla-release
./mach clobber
./mach build
for lang in `ls ../l10n/`; do
./mach build chrome-$lang
done
./mach package
'''
}
apk = sh(returnStdout: true,
script: """cd mozilla-release/objdir-frontend-android/${flavorname}/dist && \
find *.apk -not -name 'robo*' -not -name '*-unsigned-*'""").trim()
}
stage("Upload APK: ${flavorname}") {
archiveArtifacts allowEmptyArchive: true, artifacts: "mozilla-release/objdir-frontend-android/${flavorname}/dist/${apk}"
}
}
if (test == true){
try {
stage('Checkout Autobots') {
dir('autobots'){
git branch:'master',
credentialsId: 'cliqz-oss-ci',
url: 'https://github.com/cliqz-oss/cliqz-mobile-tests.git'
}
}
timeout(10) {
stage('Genymotion Status') {
def status = sh(returnStdout: true, script: """
aws ec2 describe-instance-status \
--region=$REGION \
--instance-id $INSTANCE_ID \
--query 'InstanceStatuses[].InstanceStatus[].Details[].Status' \
--output text
""").trim()
while (status != 'passed') {
println "Waiting for the instance to fully Boot up...."
sleep(15)
status = sh(returnStdout: true, script: """
aws ec2 describe-instance-status \
--region=$REGION \
--instance-id $INSTANCE_ID \
--query 'InstanceStatuses[].InstanceStatus[].Details[].Status' \
--output text
""").trim()
println "Instance Status: ${status}"
}
}
}
docker.image("${baseImageName}").inside {
withEnv([
"APP=${apk}",
"FLAVOR=${flavorname}",
"platformName=android",
"deviceName=127.0.0.1:5556",
"MODULE=testCompleteSuite",
"TEST=CompleteSuite",
"appPackage=${bundleid}",
"appActivity=org.mozilla.gecko.LauncherActivity",
"TEST_TYPE=smoke"
]) {
withCredentials([file(credentialsId: 'da5f91e6-e1ca-4aac-94ea-352b6769228b', variable: 'FILE' )]) {
stage('Genymotion ADB Connect') {
sh'''#!/bin/bash -l
set -x
set -e
chmod 400 $FILE
ssh -v -o StrictHostKeyChecking=no -i $FILE shell@$IP "setprop persist.sys.usb.config adb"
ssh -v -o StrictHostKeyChecking=no -i $FILE -NL 5556:127.0.0.1:5555 shell@$IP &
$ANDROID_HOME/platform-tools/adb connect 127.0.0.1:5556
$ANDROID_HOME/platform-tools/adb wait-for-device
'''
}
}
stage("Run Tests: ${flavorname}") {
timeout(60) {
sh'''#!/bin/bash -l
set -x
set -e
export app=$PWD/mozilla-release/objdir-frontend-android/$FLAVOR/dist/$APP
$ANDROID_HOME/platform-tools/adb install $app
cd autobots
appium --log $FLAVOR-appium.log &
echo $! > appium.pid
sleep 10
virtualenv ~/venv
source ~/venv/bin/activate
chmod 0755 requirements.txt
pip install -r requirements.txt
$ANDROID_HOME/platform-tools/adb forward tcp:6000 localfilesystem:/data/data/${appPackage}/firefox-debugger-socket
$ANDROID_HOME/platform-tools/adb forward --list
python testRunner.py || true
$ANDROID_HOME/platform-tools/adb uninstall ${appPackage}
sleep 10
$ANDROID_HOME/platform-tools/adb forward --remove-all
kill `cat appium.pid` || true
rm -f appium.pid
'''
}
}
}
stage("Upload Results: ${flavorname}") {
archiveTestResults("${flavorname}")
}
}
}catch(e) {
print e
}
}
}
}
stage('Clean Up') {
sh '''#!/bin/bash
rm -f mozilla-release/mozconfig
rm -rf mozilla-release/objdir-frontend-android
rm -rf autobots
rm -f screenshots.zip
'''
}
}
}
}
def stepsForParallelBuilds = helpers.entries(matrix).collectEntries{
[("Building ${it[0]}"):build(
name: it[0],
bundleid: it[1]['bundleid'],
target:it[1]['target'],
test:it[1]['test']
)]
}
parallel stepsForParallelBuilds
def setupTestInstance(
Boolean inTests,
String instanceImage,
String count,
String instanceType,
String keyName,
String securityGroup,
String subnetId,
String region,
Closure body
) {
if (inTests == true) {
withGenymotion(
instanceImage,
count,
instanceType,
keyName,
securityGroup,
subnetId,
region
) {
body()
}
} else {
body()
}
}
def withGenymotion(
String instanceImage,
String count,
String instanceType,
String keyName,
String securityGroup,
String subnetId,
String region,
Closure body
) {
def instance_id = ""
try {
instance_id = sh(returnStdout: true, script: """
aws ec2 run-instances \
--image-id ${instanceImage} \
--count ${count} \
--instance-type ${instanceType} \
--key-name ${keyName} \
--security-group-ids ${securityGroup} \
--subnet-id ${subnetId} \
--region=${region} \
--query "Instances[].InstanceId" \
--output text
""").trim()
def ip = sh(returnStdout: true, script: """
aws ec2 describe-instances \
--instance-ids ${instance_id} \
--region=${region} \
--query 'Reservations[].Instances[].PrivateIpAddress' \
--output text
""").trim()
sh "aws ec2 create-tags \
--resources ${instance_id} \
--region=${region} \
--tag Key=Name,Value='Appium-Genymotion'"
withEnv([
"INSTANCE_ID=${instance_id}",
"IP=${ip}",
"REGION=${region}"
]){
body()
}
} finally {
sh """#!/bin/bash -l
set -x
set -e
aws ec2 terminate-instances --instance-ids ${instance_id} --region=${region}
"""
}
}
def cloneRepoViaSSH(String repoLink, String args) {
sh """#!/bin/bash -l
set -x
set -e
mkdir -p ~/.ssh
cp $SSH_KEY ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
git clone ${args} ${repoLink}
"""
}
def archiveTestResults(String flavorName) {
try {
archiveArtifacts allowEmptyArchive: true, artifacts: 'autobots/*.log'
junit 'autobots/test-reports/*.xml'
zip archive: true, dir: 'autobots/screenshots', glob: '', zipFile: "${flavorName}-screenshots.zip"
} catch(e) {
print e
}
}