forked from tutao/tutanota
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAndroid.Jenkinsfile
172 lines (155 loc) · 4.79 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
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}"
}
agent {
label 'linux'
}
parameters {
booleanParam(name: 'PROD', defaultValue: false, description: 'Build for production')
booleanParam(
name: 'PUBLISH', defaultValue: false,
description: "Publish the app to Nexus and Google Play (when not in production mode, " +
"it will publish to the internal testing track of the tutanota-test app on Play)"
)
}
stages {
stage('Run Android tests') {
steps {
dir("${WORKSPACE}/app-android/") {
sh "./gradlew test"
}
}
}
stage('Build android app: production') {
environment {
APK_SIGN_ALIAS = "tutao.de"
}
when {
expression { params.PROD }
}
steps {
echo "Building ${VERSION}"
sh 'npm ci'
sh 'npm run build-packages'
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'
}
}
stage('Build android app: staging') {
environment {
APK_SIGN_ALIAS = "test.tutao.de"
}
when {
not { expression { params.PROD } }
}
agent {
label 'linux'
}
steps {
sh 'npm ci'
sh 'npm run build-packages'
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'
}
}
stage('Publish android app: production') {
when {
expression { params.PROD }
expression { params.PUBLISH }
}
steps {
sh 'npm ci'
unstash 'apk'
script {
def filePath = "build/app-android/tutanota-tutao-release-${VERSION}.apk"
def tag = "tutanota-android-release-${VERSION}"
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',
rolloutPercentage: '100%',
recentChangeList: [
[
language: "en-US",
text: "see: ${GITHUB_RELEASE_PAGE}"
]
]
)
sh "git tag ${tag}"
sh "git push --tags"
def checksum = sh(returnStdout: true, script: "sha256sum ${WORKSPACE}/${filePath}")
catchError(stageResult: 'UNSTABLE', buildResult: 'SUCCESS', message: 'Failed to create github release page') {
withCredentials([string(credentialsId: 'github-access-token', variable: 'GITHUB_TOKEN')]) {
sh """node buildSrc/createGithubReleasePage.js --name '${VERSION} (Android)' \
--milestone '${VERSION}' \
--tag '${tag}' \
--uploadFile '${WORKSPACE}/${filePath}' \
--platform android \
--apkChecksum ${checksum}"""
}
}
}
}
}
stage('Publish android app: staging') {
when {
not { expression { params.PROD } }
expression { params.PUBLISH }
}
steps {
script {
def util = load "jenkins-lib/util.groovy"
unstash 'apk'
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}"
]
]
)
}
}
}
}
}