-
Notifications
You must be signed in to change notification settings - Fork 683
/
Jenkinsfile
426 lines (376 loc) · 18.8 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
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
#!groovy
class DockerParameters {
// 'docker build' would normally copy the whole build-dir to the container, changing the
// docker build directory avoids that overhead
def dir = 'docker'
def args = '--device /dev/kvm:/dev/kvm ' +
'-m=12G '
def label = 'LimitedEmulator'
def image = 'catrobat/catrobat-android:api33'
}
def d = new DockerParameters()
def startEmulator(String android_version, String stageName) {
sh "adb start-server"
// creates a new avd, and if it already exists it does nothing.
sh "echo no | avdmanager create avd -f --name android${android_version} --package " +
"'system-images;android-${android_version};google_apis;x86_64' || true"
sh "/home/user/android/sdk/emulator/emulator -avd android${android_version}" +
" -logcat *:w" +
" -wipe-data -no-window -no-boot-anim -noaudio" +
" -camera-back emulated -camera-front emulated " +
" -no-snapshot-save -accel on -gpu swiftshader_indirect > ${stageName}_emulator.log 2>&1 &"
}
def waitForEmulatorAndPressWakeUpKey() {
sh 'adb devices'
sh "timeout 5m adb wait-for-device"
sh '''#!/bin/bash
adb devices
timeout 5m adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1;
done'
echo "Emulator started"
'''
// In case the device went to sleep
sh 'adb shell input keyevent KEYCODE_WAKEUP'
}
def runTestsWithEmulator(String testClass) {
sh " ./gradlew compileCatroidDebugSources compileCatroidDebugAndroidTestSources"
waitForEmulatorAndPressWakeUpKey()
sh " ./gradlew disableAnimations -PenableCoverage createCatroidDebugAndroidTestCoverageReport" +
" -Pandroid.testInstrumentationRunnerArguments.class=${testClass} "
}
def postEmulator(String coverageNameAndLogcatPrefix) {
archiveArtifacts "${coverageNameAndLogcatPrefix}_emulator.log"
zip zipFile: "${coverageNameAndLogcatPrefix}_logcat.zip", dir: "catroid/build/outputs/androidTest-results/connected/flavors/", archive: true
def jacocoReportDir = 'catroid/build/reports/coverage/androidTest/catroid/debug/connected'
if (fileExists('catroid/build/reports/coverage/androidTest/catroid/debug/connected/report.xml')) {
junitAndCoverage jacocoReportDir, 'report.xml', coverageNameAndLogcatPrefix
}
}
def junitAndCoverage(String jacocoReportDir, String jacocoReportXml, String coverageName) {
// Consume all test xml files. Otherwise tests would be tracked multiple
// times if this function was called again.
String testPattern = '**/*TEST*.xml'
junit testResults: testPattern, allowEmptyResults: true, skipPublishingChecks: true
cleanWs patterns: [[pattern: testPattern, type: 'INCLUDE']]
publishJacocoHtml jacocoReportDir, jacocoReportXml, coverageName
}
def killRunningEmulator() {
sh '''adb emu kill || true'''
sh '''#!/bin/bash
while :
do
output=$(eval "adb devices")
if [[ $output != *"emulator"* ]]; then
echo "All Emulators are killed"
echo $output
break
fi
echo "Emulator is still running"
sleep 2
done
'''
sh "adb kill-server"
}
def webTestUrlParameter() {
return env.WEB_TEST_URL?.isEmpty() ? '' : "-PwebTestUrl='${params.WEB_TEST_URL}'"
}
def allFlavoursParameters() {
return env.BUILD_ALL_FLAVOURS?.toBoolean() ? 'assembleCreateAtSchoolDebug ' +
'assembleLunaAndCatDebug assemblePhiroDebug assembleEmbroideryDesignerDebug ' +
'assemblePocketCodeBetaDebug assembleMindstormsDebug' : ''
}
def debugUnitTests() {
return env.UNIT_TEST_DEBUG?.toBoolean() ? '-i' : ''
}
def useDebugLabelParameter(defaultLabel) {
return env.DEBUG_LABEL?.trim() ? env.DEBUG_LABEL : defaultLabel
}
def useDockerLabelParameter(dockerImage, defaultLabel) {
def label = env.DOCKER_LABEL?.trim() ? env.DOCKER_LABEL : defaultLabel
return dockerImage + ':' + label
}
pipeline {
agent none
environment {
ANDROID_VERSION = 33
ADB_INSTALL_TIMEOUT = 60
}
parameters {
string name: 'WEB_TEST_URL', defaultValue: '', description: 'When set, all the archived ' +
'APKs will point to this Catrobat web server, useful for testing web changes. E.g https://web-test.catrob.at'
booleanParam name: 'BUILD_ALL_FLAVOURS', defaultValue: false, description: 'When selected all flavours are built and archived as artifacts that can be installed alongside other versions of the same APK.'
booleanParam name: 'UNIT_TEST_DEBUG', defaultValue: false, description: 'When selected the Unit Test suite prints the currently running tests and any output that it might produce'
booleanParam name: 'INCLUDE_HUAWEI_FILES', defaultValue: false, description: 'Embed any huawei files that are needed'
string name: 'DEBUG_LABEL', defaultValue: '', description: 'For debugging when entered will be used as label to decide on which slaves the jobs will run.'
string name: 'DOCKER_LABEL', defaultValue: '', description: 'When entered will be used as label for docker catrobat/catroid-android image to build'
separator(name: "Build with Paintroid",
separatorStyle: "border-width: 0",
sectionHeaderStyle: """
background-color: #ffff00;
text-align: center;
padding: 4px;
color: #000000;
font-size: 20px;
font-weight: normal;
font-family: 'Orienta', sans-serif;
letter-spacing: 1px;
font-style: italic;
""")
booleanParam name: 'BUILD_WITH_PAINTROID', defaultValue: false, description: 'Builds ' +
'catroid with paintroid develop or specified branch'
string name: 'PAINTROID_BRANCH', defaultValue: 'develop', description: 'The branch which ' +
'to build paintroid with, when BUILD_WITH_PAINTROID is enabled.'
separator(name: "TEST_STAGES", sectionHeader: "Test Stages - CAUTION: The PR needs to be rebuild again with all test stages enabled before Code Review!!",
separatorStyle: "border-width: 0",
sectionHeaderStyle: """
background-color: #ffff00;
text-align: center;
padding: 4px;
color: #000000;
font-size: 20px;
font-weight: normal;
font-family: 'Orienta', sans-serif;
letter-spacing: 1px;
font-style: italic;
""")
booleanParam name: 'PULL_REQUEST_SUITE', defaultValue: true, description: 'Enables Pull ' +
'request suite'
booleanParam name: 'STANDALONE', defaultValue: true, description: 'When selected, ' +
'standalone APK will be built'
booleanParam name: 'UNIT_TESTS', defaultValue: true, description: 'Enables Unit Tests'
booleanParam name: 'INSTRUMENTED_UNIT_TESTS', defaultValue: true, description: 'Enables ' +
'Instrumented Unit Tests'
booleanParam name: 'TESTRUNNER_TESTS', defaultValue: true, description: 'Enables ' +
'Testrunner Tests'
booleanParam name: 'QUARANTINED_TESTS', defaultValue: true, description: 'Enables ' +
'Quarantined Tests'
booleanParam name: 'RTL_TESTS', defaultValue: true, description: 'Enables RTL Tests'
booleanParam name: 'OUTGOING_NETWORK_CALL_TESTS', defaultValue: false, description: 'Enables' +
'start Outgoing web tests'
}
options {
timeout(time: 2, unit: 'HOURS')
timestamps()
buildDiscarder(logRotator(numToKeepStr: env.BRANCH_NAME == 'master' ? '10' :
env.BRANCH_NAME == 'develop' ? '5' : '2',
artifactNumToKeepStr: env.BRANCH_NAME == 'master' ? '2' :
env.BRANCH_NAME == 'develop' ? '2' : '1'
))
}
triggers {
cron(env.BRANCH_NAME == 'develop' ? '@midnight' : '')
issueCommentTrigger('.*test this please.*')
}
stages {
stage('All') {
parallel {
stage('1') {
agent {
docker {
image d.image
args d.args
label d.label
alwaysPull true
}
}
stages {
stage('APKs') {
steps {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
script {
def additionalParameters = [webTestUrlParameter(), allFlavoursParameters()].findAll {
it
}.collect()
if (additionalParameters) {
currentBuild.description = "<p>Additional APK build parameters: <b>${additionalParameters.join(' ')}</b></p>"
}
if (env.INCLUDE_HUAWEI_FILES?.toBoolean()) {
sh "cp /home/user/huawei/agconnect-services.json catroid/src/agconnect-services.json"
}
}
// Build the flavors so that they can be installed next independently of older versions.
sh "./gradlew ${webTestUrlParameter()} -Pindependent='#$env.BUILD_NUMBER $env.BRANCH_NAME' assembleCatroidDebug ${allFlavoursParameters()}"
renameApks("${env.BRANCH_NAME}-${env.BUILD_NUMBER}")
archiveArtifacts '**/*.apk'
}
}
}
stage('Build with Paintroid') {
when {
expression {
params.BUILD_WITH_PAINTROID
}
}
steps {
sh 'rm -rf Paintroid; mkdir Paintroid'
dir('Paintroid') {
git branch: params.PAINTROID_BRANCH, url: 'https://github' +
'.com/Catrobat/Paintroid.git'
sh "./gradlew assembleDebug"
sh 'rm -f ../catroid/src/main/libs/*.aar'
sh 'mv -f colorpicker/build/outputs/aar/colorpicker-debug.aar ../catroid/src/main/libs/colorpicker-LOCAL.aar'
sh 'mv -f Paintroid/build/outputs/aar/Paintroid-debug.aar ../catroid/src/main/libs/Paintroid-LOCAL.aar'
archiveArtifacts '../catroid/src/main/libs/colorpicker-LOCAL.aar'
archiveArtifacts '../catroid/src/main/libs/Paintroid-LOCAL.aar'}
}
}
stage('Static Analysis') {
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh './gradlew pmd checkstyle lintCatroidDebug detekt'
}
}
post {
always {
recordIssues aggregatingResults: true, enabledForFailure: true, qualityGates: [[threshold: 1, type: 'TOTAL', unstable: true]],
tools: [androidLintParser(pattern: 'catroid/build/reports/lint*.xml'),
checkStyle(pattern: 'catroid/build/reports/checkstyle.xml'),
pmdParser(pattern: 'catroid/build/reports/pmd.xml'),
detekt(pattern: 'catroid/build/reports/detekt/detekt.xml')]
}
}
}
stage('Unit Tests') {
when {
expression { params.UNIT_TESTS == true }
}
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh "./gradlew ${debugUnitTests()} -PenableCoverage " +
"jacocoTestCatroidDebugUnitTestReport --full-stacktrace"
junitAndCoverage 'catroid/build/reports/jacoco/jacocoTestCatroidDebugUnitTestReport', 'jacocoTestCatroidDebugUnitTestReport.xml', 'unit'
}
}
}
stage('Instrumented Unit Tests') {
when {
expression { params.INSTRUMENTED_UNIT_TESTS == true }
}
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
startEmulator(ANDROID_VERSION, 'instrumented_unit')
runTestsWithEmulator("org.catrobat.catroid.testsuites.LocalHeadlessTestSuite")
}
}
post {
always {
killRunningEmulator()
postEmulator 'instrumented_unit'
}
}
}
stage('Testrunner Tests') {
when {
expression { params.TESTRUNNER_TESTS == true }
}
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
startEmulator(ANDROID_VERSION, 'testrunner')
runTestsWithEmulator("org.catrobat.catroid.catrobattestrunner.CatrobatTestRunner")
}
}
post {
always {
killRunningEmulator()
postEmulator 'testrunner'
}
}
}
stage('Quarantined Tests') {
when {
expression { params.QUARANTINED_TESTS == true }
}
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
startEmulator(ANDROID_VERSION, "quarantined")
runTestsWithEmulator("org.catrobat.catroid.testsuites.UiEspressoQuarantineTestSuite")
}
}
post {
always {
killRunningEmulator()
postEmulator 'quarantined'
}
}
}
stage('Outgoing Network Call Tests') {
when {
expression { params.OUTGOING_NETWORK_CALL_TESTS == true }
}
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
startEmulator(ANDROID_VERSION, 'networktest')
runTestsWithEmulator("org.catrobat.catroid.testsuites.OutgoingNetworkCallsTestSuite")
}
}
post {
always {
killRunningEmulator()
postEmulator('networktest')
}
}
}
stage('RTL Tests') {
when {
expression { params.RTL_TESTS == true }
}
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
startEmulator(ANDROID_VERSION, 'rtltests')
runTestsWithEmulator("org.catrobat.catroid.testsuites.UiEspressoRtlTestSuite")
}
}
post {
always {
killRunningEmulator()
postEmulator('rtltests')
}
}
}
}
post {
always {
stash name: 'logParserRules', includes: 'buildScripts/log_parser_rules'
}
}
}
stage('2') {
agent {
docker {
image d.image
args d.args
label d.label
alwaysPull true
}
}
stages {
stage('Pull Request Suite') {
when {
expression { params.PULL_REQUEST_SUITE == true }
}
steps {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
startEmulator(ANDROID_VERSION, 'pull_request_suite')
runTestsWithEmulator("org.catrobat.catroid.testsuites.UiEspressoPullRequestTriggerSuite")
}
}
post {
always {
killRunningEmulator()
postEmulator 'pull_request_suite'
}
}
}
}
}
}
}
}
post {
changed {
node('LimitedEmulator') {
notifyChat()
}
}
}
}