forked from tutao/tutanota
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Android.Jenkinsfile
201 lines (189 loc) · 5.97 KB
/
Android.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
pipeline {
environment {
NODE_PATH = "/opt/node-v16.3.0-linux-x64/bin"
VERSION = sh(returnStdout: true, script: "${NODE_PATH}/node -p -e \"require('./package.json').version\" | tr -d \"\n\"")
APK_SIGN_STORE = '/opt/android-keystore/android.jks'
PATH = "${env.NODE_PATH}:${env.PATH}"
ANDROID_SDK_ROOT = "/opt/android-sdk-linux"
ANDROID_HOME = "/opt/android-sdk-linux"
GITHUB_RELEASE_PAGE = "https://github.com/tutao/tutanota/releases/tag/tutanota-android-release-${VERSION}"
TAG = "tutanota-android-release-${VERSION}"
}
agent {
label 'linux'
}
parameters {
booleanParam(
name: 'RELEASE', defaultValue: false,
description: "Build a test and release version of the app. " +
"Uploads both to Nexus and creates a new release on google play, " +
"which must be manually published from play.google.com/console"
)
string(
name: 'MILESTONE',
defaultValue: '',
description: 'Which github milestone to reference for generating release notes. Defaults to the version number'
)
}
stages {
stage('Test') {
steps {
dir("${WORKSPACE}/app-android/") {
sh "./gradlew test"
}
}
}
stage('Build') {
stages {
stage('Staging') {
environment {
APK_SIGN_ALIAS = "test.tutao.de"
}
agent {
label 'linux'
}
steps {
sh 'npm ci'
sh 'npm run build-packages'
script {
def util = load "jenkins-lib/util.groovy"
util.downloadFromNexus( groupId: "lib",
artifactId: "android-database-sqlcipher",
version: "4.5.0",
outFile: "${WORKSPACE}/app-android/libs/android-database-sqlcipher-4.5.0.aar",
fileExtension: 'aar')
}
withCredentials([
string(credentialsId: 'apk-sign-store-pass', variable: "APK_SIGN_STORE_PASS"),
string(credentialsId: 'apk-sign-key-pass', variable: "APK_SIGN_KEY_PASS")
]) {
sh 'node android.js -b releaseTest test'
}
stash includes: "build/app-android/tutanota-tutao-releaseTest-${VERSION}.apk", name: 'apk-staging'
}
}
stage('Production') {
when {
expression { params.RELEASE }
}
environment {
APK_SIGN_ALIAS = "tutao.de"
}
steps {
echo "Building ${VERSION}"
sh 'npm ci'
sh 'npm run build-packages'
script {
def util = load "jenkins-lib/util.groovy"
util.downloadFromNexus( groupId: "lib",
artifactId: "android-database-sqlcipher",
version: "4.5.0",
outFile: "${WORKSPACE}/app-android/libs/android-database-sqlcipher-4.5.0.aar",
fileExtension: 'aar')
}
withCredentials([
string(credentialsId: 'apk-sign-store-pass', variable: "APK_SIGN_STORE_PASS"),
string(credentialsId: 'apk-sign-key-pass', variable: "APK_SIGN_KEY_PASS")
]) {
sh 'node android.js -b release prod'
}
stash includes: "build/app-android/tutanota-tutao-release-${VERSION}.apk", name: 'apk-production'
}
}
}
}
stage('Publish') {
when {
expression { params.RELEASE }
}
stages {
stage('Staging') {
steps {
script {
def util = load "jenkins-lib/util.groovy"
unstash 'apk-staging'
util.publishToNexus(
groupId: "app",
artifactId: "android-test",
version: "${VERSION}",
assetFilePath: "${WORKSPACE}/build/app-android/tutanota-tutao-releaseTest-${VERSION}.apk",
fileExtension: 'apk'
)
// This doesn't publish to the main app on play store,
// instead it get's published to the hidden "tutanota-test" app
// this happens because the AppId is set to de.tutao.tutanota.test by the android build
// and play store knows which app to publish just based on the id
androidApkUpload(
googleCredentialsId: 'android-app-publisher-credentials',
apkFilesPattern: "build/app-android/tutanota-tutao-releaseTest-${VERSION}.apk",
trackName: 'internal',
rolloutPercentage: '100%',
recentChangeList: [
[
language: "en-US",
text : "see: ${GITHUB_RELEASE_PAGE}"
]
]
)
}
}
}
stage('Production') {
steps {
sh 'npm ci'
unstash 'apk-production'
script {
def filePath = "build/app-android/tutanota-tutao-release-${VERSION}.apk"
def util = load "jenkins-lib/util.groovy"
util.publishToNexus(
groupId: "app",
artifactId: "android",
version: "${VERSION}",
assetFilePath: "${WORKSPACE}/${filePath}",
fileExtension: 'apk'
)
androidApkUpload(
googleCredentialsId: 'android-app-publisher-credentials',
apkFilesPattern: "${filePath}",
trackName: 'production',
// Don't publish the app to users directly
// It will require manual intervention at play.google.com/console
rolloutPercentage: '0%',
recentChangeList: [
[
language: "en-US",
text : "see: ${GITHUB_RELEASE_PAGE}"
]
]
)
}
}
}
}
}
stage('Tag and publish release page') {
when {
expression { params.RELEASE }
}
steps {
// Needed to upload it
unstash 'apk-production'
sh "git tag ${TAG}"
sh "git push --tags"
script {
def filePath = "build/app-android/tutanota-tutao-release-${VERSION}.apk"
def milestone = params.MILESTONE.trim().equals("") ? VERSION : params.MILESTONE
catchError(stageResult: 'UNSTABLE', buildResult: 'SUCCESS', message: 'Failed to create github release page') {
withCredentials([string(credentialsId: 'github-access-token', variable: 'GITHUB_TOKEN')]) {
sh """node buildSrc/releaseNotes.js --releaseName '${VERSION} (Android)' \
--milestone '${milestone}' \
--tag '${tag}' \
--uploadFile '${WORKSPACE}/${filePath}' \
--platform android"""
}
}
}
}
}
}
}