-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
116 lines (97 loc) · 5.86 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
/*
* cgeo Jenkins build script. This file is checked out again for every build, so it can be version controlled with the code.
* This is work in progress and currently only used for the experimental pipeline builds but not for the default PR and commit builds (non-pipeline).
*/
// restrict to agents with an emulator
node('has-emulator') {
// display timestamps in the console output
timestamps {
// make sure notifications are sent also for failing builds using try-finally for the inner build step
try {
// group steps by stages for better monitoring in the Jenkins pipeline stage view
stage('Checkout from GitHub') {
// set timeouts for every step instead of for the complete job. default unit are minutes
timeout(5) {
// checkout the exact same version that triggered this pipeline script instead of specifying a repo and commit again
checkout scm
}
}
stage('Prepare build environment') {
timeout(5) {
// Restart the emulator to be sure of its state
sh '[ -x "$HOME"/restart-emulator.sh ] && "$HOME"/restart-emulator.sh'
// Ensure proper cleaning
sh './gradlew --no-daemon --scan clean'
sh 'rm -fr build build-cache main/build || true'
// Accept Android licenses. these are the MD5 hashes of the license texts, so they may need to be adapted on license changes
// The following line does make the build fail, needs to be investigated
// sh '[ ! -d "/opt/android-sdk-linux/licenses" ] && mkdir "/opt/android-sdk-linux/licenses"'
sh 'echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55\nd56f5187479451eabf01fb78af6dfcb131a6481e\n24333f8a63b6825ea9c5514f83c2829b004d1fee" > "/opt/android-sdk-linux/licenses/android-sdk-license"'
sh 'echo -e "\nd975f751698a77b662f1254ddbeed3901e976f5a" > "/opt/android-sdk-linux/licenses/intel-android-extra-license"'
// gradle needs the sdk.dir in local.properties. Not sure if a template exists on the server, therefore we create it on demand.
sh 'echo "sdk.dir=/opt/android-sdk-linux" > local.properties'
// get all the necessary keys
sh 'cp /srv/private.properties .'
// set the emulator preferences
sh 'cp /srv/cgeo.geocaching_preferences.xml main/cgeo.geocaching_preferences.xml'
}
}
try {
timeout(15) {
// Build sequentially instead of in one command as this made problems in the past
stage ('Run emulator tests') {
sh './gradlew --no-daemon --scan testDebug -Pandroid.testInstrumentationRunnerArguments.notAnnotation=cgeo.geocaching.test.NotForIntegrationTests'
}
stage ('Run Checkstyle tests') {
sh './gradlew --no-daemon --scan checkstyle'
}
stage ('Run Lint tests') {
sh './gradlew --no-daemon --scan lintBasicDebug'
}
}
}
finally {
stage ('Cleanup environment') {
//shutdown emulator
sh '[ -x "$HOME"/restart-emulator.sh ] && "$HOME"/restart-emulator.sh --stop'
// file cleanup
sh '[ -f private.properties ] && rm private.properties'
sh '[ -f main/cgeo.geocaching_preferences.xml ] && rm main/cgeo.geocaching_preferences.xml'
sh '[ -f main/src/main/res/values/keys.xml ] && rm main/src/main/res/values/keys.xml'
}
}
stage('Collect results') {
timeout(2) {
// archive the debug build
archive '*/build/outputs/apk/cgeo*debug.apk'
// publish JUnit results
junit '**/build/test-results/**/*.xml'
// publish checkstyle results
checkstyle canComputeNew: false, defaultEncoding: '', healthy: '', pattern: '**/reports/checkstyle/checkstyle.xml', unHealthy: ''
// publish Android Lint results
androidLint canComputeNew: false, defaultEncoding: '', healthy: '', pattern: '**/lint-results-basicDebug.xml', unHealthy: ''
// show a pragmatical programmer tip
pragprog displayLanguageCode: 'en', indicateBuildResult: false
}
}
}
finally {
// taken over from original script 2017, not yet checked whether it is working and whether it could be extended
stage ('Verify results') {
// check if emulator is out of date
if (manager.logContains(".*Your emulator is out of date.*")) {
manager.addWarningBadge("Emulator out of date.")
manager.createSummary("warning.png").appendText('Emulator out of date, see <a href="./console">console</a>.', false, false, false, "red")
}
// present the gradle build scan link on the build summary page
matcher = manager.getLogMatcher('.*(https://gradle\\S+).*')
if (matcher != null) {
url = matcher.group(1)
matcher = null // groovy cannot serialize Matcher for saving pipeline state, therefore explicitly null it out
manager.createSummary("monitor.png").appendText('Gradle build scan result available at <a href="' + url + '">' + url + '</a>', false, false, false, "black")
}
matcher = null
}
}
}
}