Expand file tree
/
Copy pathJenkinsfile
More file actions
223 lines (202 loc) · 9.41 KB
/
Copy pathJenkinsfile
File metadata and controls
223 lines (202 loc) · 9.41 KB
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
#!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 -m=6.5G'
def label = 'LimitedEmulator'
def image = 'floriankanduth/paintroid_java17:latest'
}
def dockerParameters = 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 --force --name android${android_version} --package 'system-images;android-${android_version};default;x86_64'"
sh "/home/user/android/sdk/emulator/emulator -no-window -no-boot-anim -noaudio -avd android${android_version} > ${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"
'''
sh '''
adb shell settings put global window_animation_scale 0 &
adb shell settings put global transition_animation_scale 0 &
adb shell settings put global animator_duration_scale 0 &
'''
// In case the device went to sleep
sh 'adb shell input keyevent KEYCODE_WAKEUP'
}
// NOTE: use module-agnostic report roots
def reportsGlobRoot = '**/build/reports'
// place the cobertura xml relative to the source, so that the source can be found
def javaSrc = 'Paintroid/src/main/java'
def junitAndCoverage(String jacocoXmlFile, String coverageName, String javaSrcLocation) {
// 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']]
String coverageFile = "$javaSrcLocation/coverage_${coverageName}.xml"
// Convert the JaCoCo coverage to the Cobertura XML file format.
// This is done since the Jenkins JaCoCo plugin does not work well.
sh "./buildScripts/cover2cover.py '${jacocoXmlFile}' '${coverageFile}'"
}
def useDebugLabelParameter(defaultLabel) {
return env.DEBUG_LABEL?.trim() ? env.DEBUG_LABEL : defaultLabel
}
def checkAnimationScale(scaleName) {
def output = sh(script: "adb shell settings get global ${scaleName}", returnStdout: true).trim()
if (output != "0" && output != "0.0") {
error("Animation scale '${scaleName}' is NOT disabled. Current value: ${output}")
} else {
echo("Animation scale '${scaleName}' is disabled (Value: ${output})")
}
}
pipeline {
environment {
ANDROID_VERSION = 33
ADB_INSTALL_TIMEOUT = 60
}
parameters {
string name: 'DEBUG_LABEL', defaultValue: '', description: 'For debugging when entered will be used as label to decide on which slaves the jobs will run.'
booleanParam name: 'BUILD_WITH_CATROID', defaultValue: false, description: 'When checked then the current Paintroid build will be built with the current develop branch of Catroid'
string name: 'CATROID_BRANCH', defaultValue: 'develop', description: 'The branch which to build catroid with, when BUILD_WITH_CATROID is checked.'
}
agent {
docker {
image dockerParameters.image
args dockerParameters.args
label dockerParameters.label
alwaysPull true
}
}
options {
timeout(time: 2, unit: 'HOURS')
timestamps()
buildDiscarder(logRotator(numToKeepStr: '30'))
}
triggers {
cron(env.BRANCH_NAME == 'develop' ? '@midnight' : '')
issueCommentTrigger('.*(test this please|please test this).*')
}
stages {
stage('Build Debug-APK') {
steps {
sh "./gradlew -Pindependent='#$env.BUILD_NUMBER $env.BRANCH_NAME' assembleDebug"
// archive the app debug APK
archiveArtifacts artifacts: 'app/build/outputs/apk/debug/*.apk', fingerprint: true, onlyIfSuccessful: true
plot csvFileName: 'dexcount.csv',
csvSeries: [[displayTableFlag: false, exclusionValues: '', file: 'app/build/outputs/dexcount/*.csv', inclusionFlag: 'OFF', url: '']],
group: 'APK Stats', numBuilds: '180', style: 'line', title: 'dexcount'
}
}
stage('Build with Catroid') {
when {
expression { params.BUILD_WITH_CATROID }
}
steps {
sh './gradlew publishToMavenLocal -Psnapshot'
sh 'rm -rf Catroid; mkdir Catroid'
dir('Catroid') {
git branch: params.CATROID_BRANCH, url: 'https://github.com/Catrobat/Catroid.git'
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'
}
renameApks("${env.BRANCH_NAME}-${env.BUILD_NUMBER}")
dir('Catroid') {
archiveArtifacts 'catroid/src/main/libs/*.aar'
sh './gradlew assembleCatroidDebug'
archiveArtifacts 'catroid/build/outputs/apk/catroid/debug/catroid-catroid-debug.apk'
}
}
}
stage('Static Analysis') {
steps {
// Ensure the tools actually run and generate reports
sh './gradlew pmd checkstyle lint detekt'
}
post {
always {
// Use module-agnostic patterns so we don't miss files
recordIssues(
aggregatingResults: true,
enabledForFailure: true,
qualityGates: [[threshold: 1, type: 'TOTAL', unstable: true]],
tools: [
androidLintParser(pattern: "${reportsGlobRoot}/lint-results-*.xml,${reportsGlobRoot}/lint-*.xml,${reportsGlobRoot}/lint/*.xml"),
checkStyle(pattern: "${reportsGlobRoot}/checkstyle.xml"),
pmdParser(pattern: "${reportsGlobRoot}/pmd.xml"),
detekt(pattern: "${reportsGlobRoot}/detekt/detekt.xml")
]
)
}
}
}
stage('Tests') {
stages {
stage('Unit Tests') {
steps {
sh './gradlew -PenableCoverage -Pjenkins jacocoTestDebugUnitTestReport'
}
post {
always {
// Most modules (app or Paintroid) will end up with this path
junitAndCoverage "**/build/reports/jacoco/jacocoTestDebugUnitTestReport/jacoco.xml", 'unit', javaSrc
}
}
}
stage('Device Tests') {
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
startEmulator(ANDROID_VERSION as String, 'device_tests')
waitForEmulatorAndPressWakeUpKey()
script {
checkAnimationScale("window_animation_scale")
checkAnimationScale("transition_animation_scale")
checkAnimationScale("animator_duration_scale")
}
// FIX: reference env var correctly
sh "./gradlew disableAnimations -PenableCoverage -Pjenkins -Pemulator=android${ANDROID_VERSION} -Pci createDebugCoverageReport -i"
}
}
post {
always {
sh '/home/user/android/sdk/platform-tools/adb logcat -d > logcat.txt'
sh './gradlew stopEmulator'
junitAndCoverage "**/build/reports/coverage/debug/report.xml", 'device', javaSrc
archiveArtifacts 'logcat.txt'
}
}
}
}
post {
always {
step([$class: 'CoberturaPublisher',
autoUpdateHealth: false,
autoUpdateStability: false,
coberturaReportFile: "${javaSrc}/coverage*.xml",
failUnhealthy: false, failUnstable: false, maxNumberOfBuilds: 0,
onlyStable: false, sourceEncoding: 'ASCII',
zoomCoverageChart: false, failNoReports: false])
}
}
}
}
post {
always {
step([$class: 'LogParserPublisher',
failBuildOnError: true,
projectRulePath: 'buildScripts/log_parser_rules',
unstableOnWarning: true,
useProjectRule: true])
}
changed {
notifyChat()
}
}
}