-
Notifications
You must be signed in to change notification settings - Fork 16
/
JenkinsFile
87 lines (80 loc) · 2.95 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
pipeline {
agent {
// Run on a build agent where we have the Android SDK installed
label 'android'
}
options {
// Stop the build early in case of compile or test failures
skipStagesAfterUnstable()
}
stages {
stage('Compile') {
steps {
// Compile the app and its dependencies
sh 'cd studio ; ./gradlew compileDevelopDebugSources'
}
}
stage('Unit test') {
steps {
// Compile and run the unit tests for the app and its dependencies
sh 'cd studio ; ./gradlew clean testDevelopDebugUnitTest'
// Analyse the test results and update the build result as appropriate
junit '**/TEST-*.xml'
}
}
stage('Build APK') {
steps {
// Finish building and packaging the APK
sh 'cd studio ; ./gradlew assembleDevelopDebug assembleStoreRelease'
// Archive the APKs so that they can be downloaded from Jenkins
archiveArtifacts '**/*.apk'
}
}
stage('Static analysis') {
steps {
// Run Lint and analyse the results
sh 'cd studio ; ./gradlew lintStoreRelease'
androidLint pattern: '**/lint-results-*.xml'
}
}
stage('Archive') {
steps {
dropbox configName: 'Releases', flatten: true, remoteDirectory: "'OpenGPSTracker-NG/develop/'yyyyMMdd'-build-${BUILD_NUMBER}'", remoteDirectorySDF: true, sourceFiles: '**/*-debug.apk,**/*-release.apk'
}
}
stage('Deploy') {
when {
// Only execute this stage when building from the `beta` branch
branch 'beta'
}
environment {
// Assuming a file credential has been added to Jenkins, with the ID 'my-app-signing-keystore',
// this will export an environment variable during the build, pointing to the absolute path of
// the stored Android keystore file. When the build ends, the temporarily file will be removed.
SIGNING_KEYSTORE = credentials('my-app-signing-keystore')
// Similarly, the value of this variable will be a password stored by the Credentials Plugin
SIGNING_KEY_PASSWORD = credentials('my-app-signing-password')
}
steps {
// Build the app in release mode, and sign the APK using the environment variables
sh 'cd studio ; ./gradlew assembleRelease'
// Archive the APKs so that they can be downloaded from Jenkins
archiveArtifacts '**/*.apk'
// Upload the APK to Google Play
androidApkUpload googleCredentialsId: 'Google Play', apkFilesPattern: '**/*-release.apk', trackName: 'beta'
}
post {
success {
// Notify if the upload succeeded
mail to: '[email protected]', subject: 'New build available!', body: 'Check it out!'
}
}
}
}
post {
failure {
// Notify developer team of the failure
mail to: '[email protected]', subject: 'Oops!', body: "Build ${env.BUILD_NUMBER} failed; ${env.BUILD_URL}"
}
}
}