NLDClient-yudde/Tool/build_env/jenkins_iOS_release.groovy

237 lines
11 KiB
Groovy
Raw Normal View History

2024-09-24 18:15:08 +08:00
// 对应管线任务参数
def PLATFORM_PARAM = "iOS"
def PROFILE_PARAM = "Debug"
def IPA_NAME = "NLDBuild.ipa"
def AAB_PARAM = "fasle"
// 构建时候的参数
def VERSION_PARAM = params.VERSION
def CHANNEL_PARAM = params.Channel
def DEBUGBUILD_PARAM = params.DebugBuild
def HOTUPDATE_PARAM = params.Enable_Hot_Update
// Jenkins 归档地址
def ARTIFACT_URL = "http://${env.PHXH_BUILDER_IP_ADDRESS}:8080/job/${env.JOB_NAME}/"
// 构建地址
def BUILD_PATH = "Builds/$PLATFORM_PARAM/$VERSION_PARAM"
// 日志地址
def log_path="$BUILD_PATH/build.log"
// xcode 项目相关参数
def PROJECT_NAME = "Unity-iPhone"
def SCHEME_NAME = "Unity-iPhone"
def SendMessageToWechat(message){
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"
// 转译 "\[Build Exception\]:"
def exceptionFlag = '\\[Build Exception\\]:'
2024-09-29 12:10:53 +08:00
def errorMessage = sh(script: "${WORKSPACE}/Tool/build_tools/parse_unity_build_log.sh ${logPath} error true true", returnStdout: true).trim()
2024-09-27 16:51:57 +08:00
def exceptionMessage = sh(script: "${WORKSPACE}/Tool/build_tools/parse_unity_build_log.sh ${logPath} ${exceptionFlag} false true", returnStdout: true).trim()
def sceneMessage = sh(script: "${WORKSPACE}/Tool/build_tools/parse_unity_build_log.sh ${logPath} 'Problem detected while' true true", returnStdout: true).trim()
SendMessageToWechat(errorMessage)
SendMessageToWechat(exceptionMessage)
SendMessageToWechat(sceneMessage)
}
2024-09-24 18:15:08 +08:00
def GetRemote()
{
if('Banshu' == params.Channel)
return 'shenhe';
else if('Official' == params.Channel)
return 'main'
else if('TapTap' == params.Channel)
return 'main'
else
return 'stable_dev';
}
def IsOSS()
{
if('Official' == params.Channel)
return true;
else if('TapTap' == params.Channel)
return true;
else
return false;
}
pipeline {
agent any
stages {
stage('拉最新工程') {
steps {
script {
def currentPath = sh(script: 'pwd', returnStdout: true).trim()
echo "cd ${currentPath}"
// 如果仓库存在及还原脚本存在,进行子模块还原
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"
}
def remote = GetRemote();
checkout scmGit(branches: [[name: "*/${remote}"]],
extensions: [checkoutOption(60), lfs(), cloneOption(noTags: false, reference: '', shallow: true, timeout: 120), submodule(recursiveSubmodules: true, reference: '', timeout: 1200)],
userRemoteConfigs: [[url: 'http://1.14.122.170:3000/PHXH/NLDClient.git']])
}
}
}
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 "根据 [${CHANNEL_PARAM}] 渠道修改工程"
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}"
}
}
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){
build_result=sh(script: "$WORKSPACE/Tool/build_tools/hot_update.sh ${VERSION_PARAM} ${PLATFORM_PARAM} ${PROFILE_PARAM} ${CHANNEL_PARAM} ${HOTUPDATE_PARAM}", returnStatus: true, returnStdout: false)
log_path="$BUILD_PATH/UpdatePreviousBuild.log"
}
else
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}", returnStatus: true, returnStdout: false)
2024-09-27 16:51:57 +08:00
2024-09-24 18:15:08 +08:00
// 打包失败
if(build_result != 0)
{
2024-09-27 16:51:57 +08:00
// 归档并分析日志
2024-09-24 18:15:08 +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 18:15:08 +08:00
def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Release】【${CHANNEL_PARAM}】构建失败"
SendMessageToWechat(message)
error("Failure of the '打包' stage")
}
}
}
}
stage('上传资源') {
steps {
script {
sh "chmod +x $WORKSPACE/Tool/build_tools/upload_rsync.sh"
def asset_path="$WORKSPACE/ProjectNLD/ServerData/${PLATFORM_PARAM}"
def upload_path="${CHANNEL_PARAM}/${PLATFORM_PARAM}/${VERSION_PARAM}"
def upload_result
if(IsOSS())
upload_result=sh(script: "$WORKSPACE/Tool/build_tools/upload_oss.sh ${VERSION_PARAM} ${PLATFORM_PARAM} ${CHANNEL_PARAM} ${asset_path} ${upload_path}", returnStatus: true, returnStdout: false)
else
upload_result=sh(script: "$WORKSPACE/Tool/build_tools/upload_rsync.sh ${VERSION_PARAM} ${PLATFORM_PARAM} ${CHANNEL_PARAM} ${asset_path} ${upload_path}", returnStatus: true, returnStdout: false)
if(upload_result != 0)
{
def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Release】【${CHANNEL_PARAM}】上传资源失败"
SendMessageToWechat(message)
error("Failure of the '上传资源' stage")
}
}
}
}
stage('导出IPA') {
steps {
script {
if (params.Build_InitApp == true) {
sh "chmod +x $WORKSPACE/Tool/build_tools/build_xcode_xcodeproj.sh"
sh "$WORKSPACE/Tool/build_tools/build_xcode_xcodeproj.sh ${PROJECT_NAME} ${SCHEME_NAME} ${PLATFORM_PARAM} ${VERSION_PARAM}"
}
}
}
}
stage('重命名IPA') {
steps {
script {
if (params.Build_InitApp == true) {
sh "chmod +x $WORKSPACE/Tool/build_tools/rename_ipa.sh"
sh "$WORKSPACE/Tool/build_tools/rename_ipa.sh ${VERSION_PARAM} ${PLATFORM_PARAM}"
}
}
}
}
stage('上传IPA') {
steps {
script {
// 增量更新不需要上传包体
if (params.Build_InitApp == true){
def ipa_path="$WORKSPACE/Builds/$PLATFORM_PARAM/$VERSION_PARAM/$IPA_NAME"
def upload_path="${CHANNEL_PARAM}/${PLATFORM_PARAM}"
def upload_result
if(IsOSS())
upload_result=sh(script: "$WORKSPACE/Tool/build_tools/upload_oss.sh ${VERSION_PARAM} ${PLATFORM_PARAM} ${CHANNEL_PARAM} ${ipa_path} ${upload_path}", returnStatus: true, returnStdout: false)
else
upload_result=sh(script: "$WORKSPACE/Tool/build_tools/upload_rsync.sh ${VERSION_PARAM} ${PLATFORM_PARAM} ${CHANNEL_PARAM} ${ipa_path} ${upload_path}", returnStatus: true, returnStdout: false)
if(upload_result != 0)
{
def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Release】【${CHANNEL_PARAM}】上传IPA失败"
SendMessageToWechat(message)
error("Failure of the '上传ipa' stage")
}
}
}
}
}
stage('归档') {
steps {
script {
try{
archiveArtifacts artifacts: "$log_path" , followSymlinks: false
if (params.Build_InitApp == true)
archiveArtifacts artifacts: "$BUILD_PATH/*.ipa" , 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}】【Release】【${CHANNEL_PARAM}】客户端打包上传成功!下载链接:${ARTIFACT_URL}"
SendMessageToWechat(message)
} else {
def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Release】【${CHANNEL_PARAM}】客户端增量更新上传成功!下载链接:${ARTIFACT_URL}"
SendMessageToWechat(message)
}
}
}
}
}
}