2024-09-24 17:39:15 +08:00
// 对应管线任务参数
def PLATFORM_PARAM = "Android"
def PROFILE_PARAM = "Debug"
def APK_NAME = "NLDBuild.apk"
// 构建时候的参数
def CHANNEL_PARAM = params . Channel
def DEBUGBUILD_PARAM = params . DebugBuild
def HOTUPDATE_PARAM = params . Enable_Hot_Update
def AAB_PARAM = params . AAB
2025-02-10 15:20:42 +08:00
def DEV_PARAM = true
2024-12-03 13:09:25 +08:00
def ANDROIDKEYSTORE = "/Users/mayuanzheng/key/phxh_android.keystore"
2024-12-13 19:03:12 +08:00
def ANDROIDKEYALIAS = "avery"
2024-09-24 17:39:15 +08:00
// Jenkins 归档地址
def ARTIFACT_URL = "http://${env.PHXH_BUILDER_IP_ADDRESS}:8080/job/${env.JOB_NAME}/"
2025-05-08 16:21:32 +08:00
def VERSION_PARAM // 版本号 根据项目获取
def UPLOAD_PATH_PARAM // 上传地址,根据项目获取
def ACCESS_KEY_ID_PARAM // oss id, 根据项目获取
def ACCESS_KEY_SECRET_PARAM // oss密码, 根据项目获取
def BUCKET_NAME_PARAM // oss桶名, 根据项目获取
def END_POINT_PARAM // 根据项目获取
2024-09-24 17:39:15 +08:00
// 构建地址
2024-12-17 19:36:34 +08:00
def BUILD_PATH
2024-09-24 17:39:15 +08:00
// 日志地址
2024-12-17 19:36:34 +08:00
def log_path
2024-09-24 17:39:15 +08:00
2025-02-10 15:20:42 +08:00
def GetRemote ( ) {
2025-05-08 16:21:32 +08:00
/ * if ( 'BilibiliDev' = = params . Channel )
2025-02-10 15:20:42 +08:00
return 'bilibili' ;
2025-05-08 16:21:32 +08:00
else * /
2025-02-10 15:20:42 +08:00
return 'main' ;
2024-11-06 15:58:17 +08:00
}
2024-09-24 17:39:15 +08:00
def SendMessageToWechat ( message ) {
2024-10-09 17:13:54 +08:00
if ( ! message ) {
return }
2024-09-24 17:39:15 +08:00
def INNER_ROBOT = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=3c92758c-1128-4931-ac8d-f19669d7befe"
sh "chmod +x $WORKSPACE/Tool/build_tools/send_wechat_message.sh"
sh "$WORKSPACE/Tool/build_tools/send_wechat_message.sh '${INNER_ROBOT}' '@all' '${message}'"
}
2024-09-27 16:51:57 +08:00
def ParseBuildLogError ( logPath ) {
sh "chmod +x $WORKSPACE/Tool/build_tools/parse_unity_build_log.sh"
2024-11-06 15:58:17 +08:00
// 转译 "\[Build Exception\]:" 取消使用
// def exceptionFlag = '\\[Build Exception\\]:'
2024-11-05 12:53:25 +08:00
def errorMessage = sh ( script: "${WORKSPACE}/Tool/build_tools/parse_unity_build_log.sh ${logPath} 'error CS' true true" , returnStdout: true ) . trim ( )
2024-11-06 15:58:17 +08:00
def exceptionMessage = sh ( script: "${WORKSPACE}/Tool/build_tools/parse_unity_build_log.sh ${logPath} 'Build Exception' false true" , returnStdout: true ) . trim ( )
2024-09-27 16:51:57 +08:00
def sceneMessage = sh ( script: "${WORKSPACE}/Tool/build_tools/parse_unity_build_log.sh ${logPath} 'Problem detected while' true true" , returnStdout: true ) . trim ( )
2024-10-09 17:13:54 +08:00
def multipleMessage = sh ( script: "${WORKSPACE}/Tool/build_tools/parse_unity_build_log.sh ${logPath} 'Multiple Unity' true false" , returnStdout: true ) . trim ( )
2024-10-15 19:44:22 +08:00
def processSceneMessage = sh ( script: "${WORKSPACE}/Tool/build_tools/parse_unity_build_log.sh ${logPath} 'Failed to process scene' true false" , returnStdout: true ) . trim ( )
2024-10-09 17:13:54 +08:00
2024-09-27 16:51:57 +08:00
SendMessageToWechat ( errorMessage )
SendMessageToWechat ( exceptionMessage )
SendMessageToWechat ( sceneMessage )
2024-10-09 17:13:54 +08:00
SendMessageToWechat ( multipleMessage )
2024-10-15 19:44:22 +08:00
SendMessageToWechat ( processSceneMessage )
2024-09-27 16:51:57 +08:00
}
2024-09-24 17:39:15 +08:00
pipeline {
2024-12-03 13:09:25 +08:00
//parameters
//{
//string (defaultValue: GetNextVersion(), description: '版本号', name: 'VERSION', trim: true)
//}
2024-11-06 15:58:17 +08:00
2024-09-24 17:39:15 +08:00
agent any
stages {
stage ( '拉最新工程' ) {
steps {
2025-05-08 16:21:32 +08:00
script {
def currentPath = sh ( script: 'pwd' , returnStdout: true ) . trim ( )
echo "cd ${currentPath}"
// 1. 还原子模块修改
def gitDirExists = sh ( script: '[ -d ".git" ] && echo "true" || echo "false"' , returnStdout: true ) . trim ( )
def scriptPathExists = fileExists ( "${WORKSPACE}/Tool/build_tools/git_revert_modules_modification.sh" )
if ( gitDirExists = = 'true' & & scriptPathExists ) {
sh "chmod +x $WORKSPACE/Tool/build_tools/git_revert_modules_modification.sh"
sh "$WORKSPACE/Tool/build_tools/git_revert_modules_modification.sh $WORKSPACE"
2024-09-24 17:39:15 +08:00
}
2025-05-08 16:21:32 +08:00
// 2. 拉取主项目代码
def remote = GetRemote ( ) ;
echo "拉取分支:${remote}"
checkout scmGit (
branches: [ [ name: "*/${remote}" ] ] ,
extensions: [
checkoutOption ( 60 ) ,
lfs ( ) ,
cloneOption ( noTags: false , reference: '' , shallow: false , timeout: 120 ) ,
submodule ( recursiveSubmodules: true , reference: '' , timeout: 1200 )
] ,
userRemoteConfigs: [ [ url: 'http://1.14.122.170:3000/PHXH/NLDClient.git' ] ]
)
// 3. 删除旧 GamePlay_Dll 文件夹
def gameplayDllPath = "${WORKSPACE}/ProjectNLD/Assets/Code/Scripts/GamePlay_Dll"
sh "if [ -d '${gameplayDllPath}' ]; then rm -rf '${gameplayDllPath}'; fi"
// 4. 拉取 GamePlay 仓库
def gameplayTargetPath = "${WORKSPACE}/ProjectNLD/Assets/Code/Scripts/GamePlay"
def gameplayPath = "http://1.14.122.170:3000/PHXH/GamePlay.git"
def branch = "main"
sh "chmod +x ${WORKSPACE}/Tool/build_tools/git_pull_gameplay.sh"
sh "$WORKSPACE/Tool/build_tools/git_pull_gameplay.sh ${gameplayTargetPath} ${gameplayPath} ${branch}"
2024-09-24 17:39:15 +08:00
}
}
2025-05-08 16:21:32 +08:00
}
2024-09-24 17:39:15 +08:00
stage ( '获取项目配置' ) {
steps {
// 将项目相关配置复制到打包路径下
sh "chmod +x $WORKSPACE/Tool/build_tools/copy_env.sh"
sh "$WORKSPACE/Tool/build_tools/copy_env.sh $WORKSPACE/Tool/build_env"
// 将打包机器相关配置复制到打包路径下
echo "copy local env file to $WORKSPACE"
sh "cp /Users/mayuanzheng/Builds/local_env.sh $WORKSPACE/Tool/build_tools/"
}
}
stage ( '根据渠道修改工程' ) {
steps {
echo "根据 [${params.Channel}] 渠道修改工程"
sh "chmod +x $WORKSPACE/Tool/build_tools/modify_project_by_channel.sh"
sh "$WORKSPACE/Tool/build_tools/modify_project_by_channel.sh $WORKSPACE ${CHANNEL_PARAM}"
}
}
2025-05-08 16:21:32 +08:00
stage ( '根据渠道获取相关参数' ) {
2024-12-17 19:36:34 +08:00
steps {
script {
2025-05-08 16:21:32 +08:00
echo "根据 [${params.Channel}] 渠道获取相关参数"
2024-12-27 17:29:47 +08:00
def playersettings = "$WORKSPACE/Tool/Channels/$CHANNEL_PARAM/ChannelSetting.txt"
2024-12-17 19:36:34 +08:00
sh "chmod +x $WORKSPACE/Tool/build_tools/get_build_version.sh"
2025-05-08 16:21:32 +08:00
sh "chmod +x $WORKSPACE/Tool/build_tools/get_build_upload_path.sh"
2024-12-17 19:36:34 +08:00
VERSION_PARAM = sh ( script: "$WORKSPACE/Tool/build_tools/get_build_version.sh $playersettings" , returnStdout: true ) . trim ( )
2025-05-08 16:21:32 +08:00
UPLOAD_PATH_PARAM = sh ( script: "$WORKSPACE/Tool/build_tools/get_build_upload_path.sh $playersettings" , returnStdout: true ) . trim ( )
ACCESS_KEY_ID_PARAM = sh ( script: "$WORKSPACE/Tool/build_tools/get_build_access_key.sh $playersettings" , returnStdout: true ) . trim ( )
ACCESS_KEY_SECRET_PARAM = sh ( script: "$WORKSPACE/Tool/build_tools/get_build_access_key_secret.sh $playersettings" , returnStdout: true ) . trim ( )
BUCKET_NAME_PARAM = sh ( script: "$WORKSPACE/Tool/build_tools/get_build_bucket_name.sh $playersettings" , returnStdout: true ) . trim ( )
END_POINT_PARAM = sh ( script: "$WORKSPACE/Tool/build_tools/get_build_end_point.sh $playersettings" , returnStdout: true ) . trim ( )
2024-12-17 19:36:34 +08:00
BUILD_PATH = "Builds/$CHANNEL_PARAM/$PLATFORM_PARAM/$VERSION_PARAM"
log_path = "$BUILD_PATH/build.log"
2025-05-08 16:21:32 +08:00
echo "获取到的版本是 $VERSION_PARAM, 获取到的上传地址是 $UPLOAD_PATH_PARAM, 获取到的ossId是 $ACCESS_KEY_ID_PARAM, 获取到的oss密码是 $ACCESS_KEY_SECRET_PARAM, 获取到的oss桶名是 $BUCKET_NAME_PARAM, 获取到的oss endPoint是 $END_POINT_PARAM"
2024-12-17 19:36:34 +08:00
}
}
}
2024-09-24 17:39:15 +08:00
stage ( '打包' ) {
steps {
sh "chmod +x $WORKSPACE/Tool/build_tools/build_unity.sh"
sh "chmod +x $WORKSPACE/Tool/build_tools/hot_update.sh"
script {
def build_result
if ( params . Debug_AllLocal = = true )
PROFILE_PARAM = "AllLocal"
if ( params . Build_InitApp = = false ) {
2024-12-27 17:29:47 +08:00
build_result = sh ( script: "$WORKSPACE/Tool/build_tools/hot_update.sh ${VERSION_PARAM} ${PLATFORM_PARAM} ${PROFILE_PARAM} ${CHANNEL_PARAM} ${HOTUPDATE_PARAM} ${DEBUGBUILD_PARAM} ${ANDROIDKEYSTORE} ${ANDROIDKEYALIAS}" , returnStatus: true , returnStdout: false )
2024-09-24 17:39:15 +08:00
log_path = "$BUILD_PATH/UpdatePreviousBuild.log"
}
else
2025-05-08 16:21:32 +08:00
build_result = sh ( script: "$WORKSPACE/Tool/build_tools/build_unity.sh ${VERSION_PARAM} ${PLATFORM_PARAM} ${PROFILE_PARAM} ${CHANNEL_PARAM} ${HOTUPDATE_PARAM} ${DEBUGBUILD_PARAM} ${AAB_PARAM} ${DEV_PARAM} ${ACCESS_KEY_ID_PARAM} ${ACCESS_KEY_SECRET_PARAM} ${BUCKET_NAME_PARAM} ${END_POINT_PARAM} ${ANDROIDKEYSTORE} ${ANDROIDKEYALIAS}" , returnStatus: true , returnStdout: false )
2024-09-24 17:39:15 +08:00
// 打包失败
if ( build_result ! = 0 )
{
2024-09-27 16:51:57 +08:00
// 归档并分析日志
2024-09-24 17:39:15 +08:00
archiveArtifacts artifacts: "$log_path" , followSymlinks: false
def parse_log = "../../$log_path"
2024-09-27 16:51:57 +08:00
ParseBuildLogError ( parse_log )
2024-09-24 17:39:15 +08:00
2024-09-26 16:51:33 +08:00
def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Debug】【${CHANNEL_PARAM}】构建失败"
2024-09-24 17:39:15 +08:00
SendMessageToWechat ( message )
error ( "Failure of the '打包' stage" )
}
}
}
}
stage ( '上传资源' ) {
steps {
script {
2025-02-10 15:20:42 +08:00
sh "chmod +x $WORKSPACE/Tool/build_tools/upload_oss.sh"
2024-09-24 17:39:15 +08:00
def asset_path = "$WORKSPACE/ProjectNLD/ServerData/${PLATFORM_PARAM}"
2025-05-08 16:21:32 +08:00
def upload_path = "${UPLOAD_PATH_PARAM}/${CHANNEL_PARAM}/${PLATFORM_PARAM}/${VERSION_PARAM}"
2025-02-10 15:20:42 +08:00
def upload_result = 0
2025-05-08 16:21:32 +08:00
upload_result = sh ( script: "$WORKSPACE/Tool/build_tools/upload_oss.sh ${asset_path} ${upload_path}" , returnStatus: true , returnStdout: false )
2025-02-10 15:20:42 +08:00
2024-09-24 17:39:15 +08:00
if ( upload_result ! = 0 )
{
2024-09-26 16:51:33 +08:00
def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Debug】【${CHANNEL_PARAM}】上传资源失败"
2024-09-24 17:39:15 +08:00
SendMessageToWechat ( message )
error ( "Failure of the '上传资源' stage" )
}
}
}
}
stage ( '上传apk' ) {
steps {
script {
// 增量更新不需要上传包体
if ( params . Build_InitApp = = true ) {
2024-10-16 13:40:29 +08:00
def apk_path = "$WORKSPACE/Builds/$CHANNEL_PARAM/$PLATFORM_PARAM/$VERSION_PARAM/$APK_NAME"
2025-05-08 16:21:32 +08:00
def upload_path = "${UPLOAD_PATH_PARAM}/${CHANNEL_PARAM}/${PLATFORM_PARAM}"
def upload_path_with_version = "${UPLOAD_PATH_PARAM}/${CHANNEL_PARAM}/${PLATFORM_PARAM}/${VERSION_PARAM}"
2025-02-10 15:20:42 +08:00
def upload_result = 0
def upload_result_with_version = 0
2025-05-08 16:21:32 +08:00
upload_result = sh ( script: "$WORKSPACE/Tool/build_tools/upload_oss.sh ${apk_path} ${upload_path}" , returnStatus: true , returnStdout: false )
upload_result_with_version = sh ( script: "$WORKSPACE/Tool/build_tools/upload_oss.sh ${apk_path} ${upload_path_with_version}" , returnStatus: true , returnStdout: false )
2024-12-13 19:03:12 +08:00
if ( upload_result ! = 0 | | upload_result_with_version ! = 0 )
2024-09-24 17:39:15 +08:00
{
2024-09-26 16:51:33 +08:00
def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Debug】【${CHANNEL_PARAM}】上传APK失败"
2024-09-24 17:39:15 +08:00
SendMessageToWechat ( message )
error ( "Failure of the '上传apk' stage" )
}
}
}
}
}
2024-09-26 16:51:33 +08:00
stage ( '上传符号表' ) {
steps {
script {
// 增量更新不需要上传符号表
sh "chmod +x $WORKSPACE/Tool/build_tools/upload_symbol_file.sh"
if ( params . Build_InitApp = = true ) {
2024-12-27 17:29:47 +08:00
def playersettings = "$WORKSPACE/Tool/Channels/$CHANNEL_PARAM/ChannelSetting.txt"
2024-10-16 13:40:29 +08:00
def symbol_path = "$WORKSPACE/Builds/$CHANNEL_PARAM/$PLATFORM_PARAM/$VERSION_PARAM"
2024-12-17 19:54:01 +08:00
def upload_result = sh ( script: "$WORKSPACE/Tool/build_tools/upload_symbol_file.sh ${VERSION_PARAM} ${PLATFORM_PARAM} ${symbol_path} ${playersettings}" , returnStatus: true , returnStdout: false )
2024-09-26 16:51:33 +08:00
if ( upload_result ! = 0 )
{
2024-09-27 11:39:40 +08:00
def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Debug】【${CHANNEL_PARAM}】上传符号表异常"
2024-09-26 16:51:33 +08:00
SendMessageToWechat ( message )
}
}
}
}
}
2024-09-24 17:39:15 +08:00
stage ( '归档' ) {
steps {
script {
try {
archiveArtifacts artifacts: "$log_path" , followSymlinks: false
if ( params . Build_InitApp = = true )
archiveArtifacts artifacts: "$BUILD_PATH/*.apk" , followSymlinks: false
}
catch ( Exception e ) {
SendMessageToWechat ( e . message + "\r\n" + e . stackTrace )
currentBuild . result = 'FAILURE'
return
}
}
}
}
stage ( '通知' ) {
steps {
script {
if ( params . Build_InitApp = = true ) {
def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Debug】【${CHANNEL_PARAM}】客户端打包上传成功!下载链接:${ARTIFACT_URL}"
SendMessageToWechat ( message )
} else {
def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Debug】【${CHANNEL_PARAM}】客户端增量更新上传成功!下载链接:${ARTIFACT_URL}"
SendMessageToWechat ( message )
}
}
}
}
}
}