forked from Catrobat/Catroid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
369 lines (329 loc) · 18.1 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
#!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 -v /var/local/container_shared/gradle_cache/$EXECUTOR_NUMBER:/home/user/.gradle -v /var/local/container_shared/huawei:/home/user/huawei -m=8G'
def label = 'LimitedEmulator'
def image = 'catrobat/catrobat-android:stable'
}
def d = new DockerParameters()
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 postEmulator(String coverageNameAndLogcatPrefix) {
sh './gradlew stopEmulator'
def jacocoReportDir = 'catroid/build/reports/coverage/catroid/debug'
if (fileExists('catroid/build/reports/coverage/catroid/debug/report.xml')){
junitAndCoverage jacocoReportDir, 'report.xml', coverageNameAndLogcatPrefix
archiveArtifacts "${coverageNameAndLogcatPrefix}_logcat.txt"
}
}
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
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"""
sh 'mkdir -p catroid/build/reports/jacoco/jacocoTestCatroidDebugUnitTestReport/'
sh 'touch catroid/build/reports/jacoco/jacocoTestCatroidDebugUnitTestReport/jacocoTestCatroidDebugUnitTestReport.xml'
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') {
sh '''./gradlew -PenableCoverage -PlogcatFile=instrumented_unit_logcat.txt -Pemulator=android28 \
startEmulator createCatroidDebugAndroidTestCoverageReport \
-Pandroid.testInstrumentationRunnerArguments.class=org.catrobat.catroid.testsuites.LocalHeadlessTestSuite'''
}
}
post {
always {
postEmulator 'instrumented_unit'
}
}
}
stage('Testrunner Tests') {
when {
expression { params.TESTRUNNER_TESTS == true }
}
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh '''./gradlew -PenableCoverage -PlogcatFile=testrunner_logcat.txt -Pemulator=android28 \
startEmulator createCatroidDebugAndroidTestCoverageReport \
-Pandroid.testInstrumentationRunnerArguments.package=org.catrobat.catroid.catrobattestrunner'''
}
}
post {
always {
postEmulator 'testrunner'
}
}
}
stage('Quarantined Tests') {
when {
expression { params.QUARANTINED_TESTS == true }
}
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh '''./gradlew -PenableCoverage -PlogcatFile=quarantined_logcat.txt -Pemulator=android28 \
startEmulator createCatroidDebugAndroidTestCoverageReport \
-Pandroid.testInstrumentationRunnerArguments.class=org.catrobat.catroid.testsuites.UiEspressoQuarantineTestSuite'''
}
}
post {
always {
postEmulator 'quarantined'
}
}
}
stage('Outgoing Network Call Tests') {
when {
expression { params.OUTGOING_NETWORK_CALL_TESTS == true }
}
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE')
{
sh '''./gradlew -PenableCoverage -Pemulator=android28 \
startEmulator createCatroidDebugAndroidTestCoverageReport \
-Pandroid.testInstrumentationRunnerArguments.class=org.catrobat.catroid.testsuites.OutgoingNetworkCallsTestSuite'''
}
}
post {
always {
junit '**/*TEST*.xml'
sh './gradlew stopEmulator clearAvdStore'
archiveArtifacts 'logcat.txt'
}
}
}
stage('RTL Tests') {
when {
expression { params.RTL_TESTS == true }
}
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh '''./gradlew -PenableCoverage -PlogcatFile=rtltests_logcat.txt -Pemulator=android28 \
startEmulator createCatroidDebugAndroidTestCoverageReport \
-Pandroid.testInstrumentationRunnerArguments.class=org.catrobat.catroid.testsuites.UiEspressoRtlTestSuite'''
}
}
post {
always {
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') {
sh '''./gradlew copyAndroidNatives -PenableCoverage -PlogcatFile=pull_request_suite_logcat.txt -Pemulator=android28 \
startEmulator createCatroidDebugAndroidTestCoverageReport \
-Pandroid.testInstrumentationRunnerArguments.class=org.catrobat.catroid.testsuites.UiEspressoPullRequestTriggerSuite'''
}
}
post {
always {
postEmulator 'pull_request_suite'
}
}
}
}
}
}
}
}
post {
changed {
node('master') {
notifyChat()
}
}
}
}