-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
113 lines (97 loc) · 3.02 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
#!groovy
BUILD_URL = "${env.BUILD_URL}"
BUILD_TYPE = "${env.BUILD_TYPE}" // e.g. "Debug", "Release"
BUILD_NUMBER = "${env.BUILD_NUMBER}"
EMAIL = "${env.EMAIL}"
PORT_EMU_1 = "${env.PORT_EMU_1}"
PORT_EMU_2 = "${env.PORT_EMU_2}"
REPORT_PATH_UNIT_TESTS = 'app/build/test-results/testDebugUnitTest/debug'
REPORT_PATH_INSTRUMENTED_TESTS = 'app/build/outputs/androidTest-results/connected'
node {
checkout()
assemble()
runUnitTests()
runInstrumentedTests()
sendEmailSuccess()
}
void checkout() {
stage('Checkout') {
checkout scm
}
}
void assemble() {
stage('Assemble') {
// Remove reports from previous build
sh "rm -rf ../htmlreports/"
sh "./gradlew clean assemble$BUILD_TYPE"
}
}
void runUnitTests() {
stage('Unit Tests') {
try {
sh "./gradlew --stacktrace testDebug"
} catch (error) {
sendEmailFail()
throw error
}
Throwable error = publishUnitTestReport()
if (error != null) {
sendEmailFail()
throw error
}
}
}
void runInstrumentedTests() {
stage('Instrumented Tests') {
sh './gradlew assembleDebugAndroidTest'
parallel(
emu1: {
runInstrumentedTestOnEmu("-Pandroid.testInstrumentationRunnerArguments.class=com.google.samples.apps.topeka.activity.SignInActivityTest -Pdevices=emulator-$PORT_EMU_1")
},
emu2: {
runInstrumentedTestOnEmu("-Pandroid.testInstrumentationRunnerArguments.class=com.google.samples.apps.topeka.activity.CategorySelectionActivityTest -Pdevices=emulator-$PORT_EMU_2")
},
failFast: true
)
Throwable error = publishInstrumentedTestReport()
if (error != null) {
sendEmailFail()
throw error
}
}
}
void runInstrumentedTestOnEmu(String param) {
try {
sh "./gradlew connectedDebugAndroidTest --stacktrace --info $param"
} catch (error) {
sendEmailFail()
throw error
}
}
void publishUnitTestReport() {
Throwable error = null
try {
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: REPORT_PATH_UNIT_TESTS, reportFiles: 'index.html', reportName: 'Unit tests report'])
} catch (e) {
error = e
}
error
}
void publishInstrumentedTestReport() {
Throwable error = null
try {
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: REPORT_PATH_INSTRUMENTED_TESTS, reportFiles: 'index.html', reportName: 'Instrumented tests report'])
} catch (e) {
error = e
}
error
}
void sendEmailSuccess() {
emailext body: BUILD_URL, subject: "Build $BUILD_NUMBER succeeded", to: EMAIL
}
void sendEmailFail() {
if(currentBuild.result != 'FAILURE') {
currentBuild.result = 'FAILURE'
step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: EMAIL, sendToIndividuals: true])
}
}