forked from Catrobat/Catroid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
268 lines (230 loc) · 12.5 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
#!groovy
class DockerParameters {
def image = 'catrobat/catrobat-android'
def imageLabel = 'stable'
def args = '--device /dev/kvm:/dev/kvm -v /var/local/container_shared/gradle_cache/$EXECUTOR_NUMBER:/home/user/.gradle -m=14G'
def label = 'LimitedEmulator'
}
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
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'
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 assembleArduinoDebug' : ''
}
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.'
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'
}
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 useDockerLabelParameter(d.image, d.imageLabel)
args d.args
label useDebugLabelParameter(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>"
}
}
// Checks that the creation of standalone APKs (APK for a Pocketcode app) works, reducing the risk of breaking gradle changes.
// The resulting APK is not verified itself.
sh """./gradlew copyAndroidNatives assembleStandaloneDebug ${webTestUrlParameter()} -Papk_generator_enabled=true -Psuffix=generated817.catrobat \
-Pdownload='https://share.catrob.at/pocketcode/download/817.catrobat'"""
// 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('Static Analysis') {
steps {
catchError(buildResult: 'FAILURE', 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') {
steps {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
sh './gradlew -PenableCoverage jacocoTestCatroidDebugUnitTestReport'
}
}
post {
always {
junitAndCoverage 'catroid/build/reports/jacoco/jacocoTestCatroidDebugUnitTestReport', 'jacocoTestCatroidDebugUnitTestReport.xml', 'unit'
}
}
}
stage('Instrumented Unit Tests') {
steps {
catchError(buildResult: 'FAILURE', 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') {
steps {
catchError(buildResult: 'FAILURE', 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 { isJobStartedByTimer() }
}
steps {
catchError(buildResult: 'FAILURE', 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('RTL Tests') {
steps {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
sh '''./gradlew -PenableCoverage -PlogcatFile=rtltests_logcat.txt -Pemulator=android24 \
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 useDockerLabelParameter(d.image, d.imageLabel)
args d.args
label useDebugLabelParameter(d.label)
alwaysPull true
}
}
stages {
stage('Pull Request Suite') {
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 {
always {
node('master') {
unstash 'logParserRules'
step([$class: 'LogParserPublisher', failBuildOnError: true, projectRulePath: 'buildScripts/log_parser_rules', unstableOnWarning: true, useProjectRule: true])
}
}
changed {
node('master') {
notifyChat()
}
}
}
}