forked from seayoo-io/combo-demo-unity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile.android
263 lines (247 loc) · 9.85 KB
/
Jenkinsfile.android
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#!/usr/bin/env groovy
DISTRO_LIST = ['android', 'xiaomi', 'google_play', 'vivo', 'uc', 'oppo', 'huawei', 'taptap', 'honor', 'm4399', 'bilibili', 'yingyongbao', 'douyin', 'promo_kuaishou', 'promo_douyin', 'promo_tencent', 'leidian', 'maowo', 'lenovo', 'meizu', 'coolpad', 'nubia', 'meituo', 'juefeng']
def JDK_VERSION = 'amazon-corretto-11.0.21.9.1'
def callUnity(Map map = [:]) {
def project = map.get('project', '.')
def commands = map.get('commands', '')
def defaultLogFile = env.STAGE_NAME.replaceAll("\\s", "-").toLowerCase()
def logFile = map.get('logFile', "logs/${defaultLogFile}.log")
sh "${env.UNITY_ROOT} -projectPath ${project} -quit -batchmode ${commands} -logFile ${logFile}"
}
def downloadUnitySDK() {
build job: params.UNITY_SDK_PROJECT_NAME, propagate: true, wait: true
def unitySDKZip = "*.zip"
copyArtifacts projectName: "${params.UNITY_SDK_PROJECT_NAME}", selector: lastSuccessful(), filter: unitySDKZip
def files = findFiles glob: unitySDKZip
unzip zipFile: files[0].name, dir: env.UNITY_SDK_PATH, quiet: true
}
def writeComboYaml(buildKey) {
def endpoint = getEndpoint()
def gameId = params.GAME_ID
writeFile file: 'combo.yaml', text: """
combo:
game-id: ${gameId}
build-key: ${buildKey}
endpoint: ${endpoint}
"""
}
def installComboCLI() {
def comboZip = "combo_main_darwin_arm64.zip"
copyArtifacts projectName: 'SDK/Client/Combo/cli/main', filter: comboZip
unzip comboZip
}
def getTargetDistros() {
return DISTRO_LIST.join(',')
}
def setVisibleItemCount() {
return DISTRO_LIST.size()
}
def getEndpoint() {
if (params.UI_MODE == "global" && params.TARGET_ENV == "dev") {
return "https://nv3fcfg4-8091.inc1.devtunnels.ms"
}
return (params.TARGET_ENV == "dev") ? "https://api.dev.seayoo.com" : "https://api.seayoo.com"
}
def getDemoEndpoint() {
return (params.TARGET_ENV == "dev") ? "https://combo-demo.dev.seayoo.com" : "https://combo-demo.seayoo.com"
}
pipeline {
agent {
node {
label 'combo-demo:android'
}
}
options {
skipDefaultCheckout()
disableConcurrentBuilds()
buildDiscarder(logRotator(
daysToKeepStr: '15',
artifactNumToKeepStr: '20'
))
ansiColor('xterm')
timestamps()
}
parameters {
choice(name: 'GAME_ID', choices: ['demo', 'catsnsoup'], description: 'GAME_ID')
choice(name: 'UI_MODE', choices: ['china', 'global'], description: '国内/海外')
choice(name: 'TARGET_ENV', choices: ['dev', 'prod'], description: '选择线上/测试环境')
extendedChoice(
name: 'DISTRO',
type: 'PT_MULTI_SELECT',
description: '选择发布的模块, 支持多选 (按住 Ctrl 键并单击每一个选项;或者按住 Shift 键并单击要选的第一个选项和要选的最后一个选项以圈定范围)',
value: getTargetDistros(),
defaultValue: 'android',
multiSelectDelimiter: ',',
quoteValue: false,
saveJSONParameterToFile: false,
visibleItemCount: setVisibleItemCount()
)
string(name: 'BUNDLE_VERSION', defaultValue: '1.0.0', description: 'Demo Bundle Version', trim: true)
choice(name: 'CHECK_UPDATE', choices: ['SKIP_UPDATE', 'HOT_UPDATE', 'FORCE_UPDATE'], description: '模拟游戏的检查更新行为: SKIP_UPDATE-不更新; HOT_UPDATE-热更新; FORCE_UPDATE-强制更新')
string(name: 'UNITY_SDK_PROJECT_NAME',
defaultValue: "SDK/Client/Combo/unity/${env.BRANCH_NAME}",
description: 'Unity SDK 工程的 Jenkins Full project name',
trim: true)
choice(name: 'BUILD_TYPE', choices: ['release', 'debug'], description: '默认不需要关心')
booleanParam(name: 'ENABLE_KEEP_RENDERING_ON_PAUSE',
defaultValue: false,
description: 'When checked, will open EnableKeepRenderingOnPause.')
booleanParam(name: 'CLEAN_WS',
defaultValue: false,
description: 'When checked, will clean workspace.')
}
environment {
UNITY_ROOT = getUnityRoot('2019.4.40f1')
ANDROID_ROOT = "build"
UNITY_SDK_PATH = "${env.WORKSPACE}/Packages"
}
stages {
stage('Clean and Setup') {
steps {
script {
if (params.CLEAN_WS) {
cleanWs()
}
sh """
rm -rf ${env.ANDROID_ROOT}/APKs
rm -rf *.zip
rm -rf *.apk
rm -rf logs/*
rm -rf "${env.UNITY_SDK_PATH}/com.seayoo.sdk"
"""
}
}
}
stage('Checkout') {
steps {
script {
checkout scm
// For Unity Build
sh 'mkdir -p logs'
}
}
}
stage('Integrate UnitySDK') {
steps {
script {
downloadUnitySDK()
}
}
}
stage('Switch Platform') {
steps {
script {
def platformFile = 'platform.txt'
if (fileExists(platformFile)) {
echo 'Current platform was already Android, skip switch.'
} else {
callUnity commands: '-buildTarget Android'
writeFile file: platformFile, text: 'Android'
}
}
}
}
stage('Update Settings') {
environment {
COMBOSDK_GAME_ID = "${params.GAME_ID}"
COMBOSDK_ENDPOINT = getEndpoint()
ENABLE_KEEP_RENDERING_ON_PAUSE = "${params.ENABLE_KEEP_RENDERING_ON_PAUSE}"
}
steps {
script {
def credentialsId = "combo-${params.GAME_ID}.publishable-key"
withCredentials([string(variable: 'COMBOSDK_PUBLISHABLE_KEY', credentialsId: credentialsId)]) {
callUnity commands: "-executeMethod Builder.UpdateComboSDKSettings"
}
}
}
}
stage('Export Project') {
environment {
EXPORT_PATH = "${env.WORKSPACE}/build"
DEMO_ENDPOINT = getDemoEndpoint()
BUNDLE_VERSION = "${params.BUNDLE_VERSION}"
CHECK_UPDATE = "${params.CHECK_UPDATE}"
}
steps {
script {
withAndroidSdk("r30.0.2") {
withAndroidNdk("r16b") {
callUnity commands: "-executeMethod Builder.BuildAndroidDemo"
}
}
}
}
}
stage('Build APKs') {
tools {
jdk JDK_VERSION
}
steps {
script {
installComboCLI()
sh 'chmod +x ./combo'
dir(env.ANDROID_ROOT) {
withGradle('6.9.4') {
def credentialsId = "combo-${params.GAME_ID}.build-key"
withCredentials([string(variable: 'COMBOSDK_BUILD_KEY', credentialsId: credentialsId)]) {
writeComboYaml(COMBOSDK_BUILD_KEY)
}
sh "${env.WORKSPACE}/combo android build --distros ${params.DISTRO}"
}
}
}
}
}
stage('Archive') {
steps {
script {
def distros = params.DISTRO.split(',')
distros.each { distro ->
def apkName = artifactName(name: "combo-demo", suffix: "-${distro}", extension: "apk")
sh "find ${env.ANDROID_ROOT}/APKs -name '${distro}*.apk' -exec mv {} ${env.WORKSPACE}/${apkName} \\;"
}
archiveArtifacts artifacts: '*.apk', onlyIfSuccessful: true
}
}
}
stage('Upload Symbol') {
steps {
withSentryCLI() {
withCredentials([string(variable: 'SENTRY_TOKEN', credentialsId: ' sentry-token.seayoo-cn')]) {
sh """sentry-cli-Darwin-universal --url=https://sentry.seayoo.com upload-dif \
--org sentry \
--project combo-demo \
--auth-token ${SENTRY_TOKEN} \
--wait ${env.ANDROID_ROOT}/unityLibrary/src/main/jniLibs/ """
}
}
}
}
}
post {
success {
script {
def downloads = []
def distros = params.DISTRO.split(',')
distros.each { distro ->
def apkName = artifactName(name: "combo-demo", suffix: "-${distro}", extension: "apk")
downloads += [
'name': "[${distro}]", 'url': "${env.BUILD_URL}artifact/${apkName}"
]
}
notify withChanges: true, downloads: downloads, what: "**distro: ${params.DISTRO}**"
}
}
failure {
notify withChanges: true, withErrors: true, what: "**distro: ${params.DISTRO}**"
}
always {
script {
currentBuild.displayName = "${BUILD_DISPLAY_NAME} ${params.GAME_ID} ${params.TARGET_ENV}"
currentBuild.description = "distro: ${params.DISTRO}"
zip archive: true, zipFile: 'logs.zip', dir: 'logs'
}
}
}
}