更新jenkins脚本 -ios打包 添加失败消息通知

main
zhangaotian 2025-06-19 15:15:07 +08:00
parent 4d40de5a07
commit 936b85e700
2 changed files with 225 additions and 113 deletions

View File

@ -62,77 +62,105 @@ pipeline {
stages {
stage('拉最新工程') {
steps {
script {
def currentPath = sh(script: 'pwd', returnStdout: true).trim()
echo "cd ${currentPath}"
script {
try {
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"
}
// 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"
}
// 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']]
)
// 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"
// 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 = GetRemote();
sh "chmod +x ${WORKSPACE}/Tool/build_tools/git_pull_gameplay.sh"
sh "$WORKSPACE/Tool/build_tools/git_pull_gameplay.sh ${gameplayTargetPath} ${gameplayPath} ${branch}"
// 4. GamePlay
def gameplayTargetPath = "${WORKSPACE}/ProjectNLD/Assets/Code/Scripts/GamePlay"
def gameplayPath = "http://1.14.122.170:3000/PHXH/GamePlay.git"
def branch = GetRemote();
sh "chmod +x ${WORKSPACE}/Tool/build_tools/git_pull_gameplay.sh"
sh "$WORKSPACE/Tool/build_tools/git_pull_gameplay.sh ${gameplayTargetPath} ${gameplayPath} ${branch}"
} catch (err) {
def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Debug】【${CHANNEL_PARAM}】拉最新工程失败"
SendMessageToWechat(message)
error("Failure of the '拉最新工程' stage")
}
}
}
}
}
stage('获取项目配置') {
steps {
//
sh "chmod +x $WORKSPACE/Tool/build_tools/copy_env.sh"
sh "$WORKSPACE/Tool/build_tools/copy_env.sh $WORKSPACE/Tool/build_env"
script {
try {
//
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/"
//
echo "copy local env file to $WORKSPACE"
sh "cp /Users/mayuanzheng/Builds/local_env.sh $WORKSPACE/Tool/build_tools/"
} catch (err) {
def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Debug】【${CHANNEL_PARAM}】获取项目配置失败"
SendMessageToWechat(message)
error("Failure of the '获取项目配置' stage")
}
}
}
}
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}"
script {
try {
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}"
} catch (err) {
def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Debug】【${CHANNEL_PARAM}】根据渠道修改工程失败"
SendMessageToWechat(message)
error("Failure of the '根据渠道修改工程' stage")
}
}
}
}
stage('根据渠道获取相关参数') {
steps {
script {
echo "根据 [${params.Channel}] 渠道获取相关参数"
def playersettings = "$WORKSPACE/Tool/Channels/$CHANNEL_PARAM/ChannelSetting.txt"
sh "chmod +x $WORKSPACE/Tool/build_tools/get_build_version.sh"
sh "chmod +x $WORKSPACE/Tool/build_tools/get_build_upload_path.sh"
sh "chmod +x $WORKSPACE/Tool/build_tools/get_build_assets_end_point.sh"
VERSION_PARAM = sh(script: "$WORKSPACE/Tool/build_tools/get_build_version.sh $playersettings", returnStdout: true).trim()
OSS_UPLOAD_PATH_PARAM = sh(script: "$WORKSPACE/Tool/build_tools/get_build_upload_path.sh $playersettings", returnStdout: true).trim()
ASSETS_END_POINT_PARAM = sh(script: "$WORKSPACE/Tool/build_tools/get_build_assets_end_point.sh $playersettings", returnStdout: true).trim()
BUILD_PATH = "Builds/$CHANNEL_PARAM/$PLATFORM_PARAM/$VERSION_PARAM"
log_path="$BUILD_PATH/build.log"
echo "获取到的版本是 ${VERSION_PARAM}, 获取到的上传地址是 ${OSS_UPLOAD_PATH_PARAM}获取到的assets-oss-endpoint是 ${ASSETS_END_POINT_PARAM}"
try {
echo "根据 [${params.Channel}] 渠道获取相关参数"
def playersettings = "$WORKSPACE/Tool/Channels/$CHANNEL_PARAM/ChannelSetting.txt"
sh "chmod +x $WORKSPACE/Tool/build_tools/get_build_version.sh"
sh "chmod +x $WORKSPACE/Tool/build_tools/get_build_upload_path.sh"
sh "chmod +x $WORKSPACE/Tool/build_tools/get_build_assets_end_point.sh"
VERSION_PARAM = sh(script: "$WORKSPACE/Tool/build_tools/get_build_version.sh $playersettings", returnStdout: true).trim()
OSS_UPLOAD_PATH_PARAM = sh(script: "$WORKSPACE/Tool/build_tools/get_build_upload_path.sh $playersettings", returnStdout: true).trim()
ASSETS_END_POINT_PARAM = sh(script: "$WORKSPACE/Tool/build_tools/get_build_assets_end_point.sh $playersettings", returnStdout: true).trim()
BUILD_PATH = "Builds/$CHANNEL_PARAM/$PLATFORM_PARAM/$VERSION_PARAM"
log_path="$BUILD_PATH/build.log"
echo "获取到的版本是 ${VERSION_PARAM}, 获取到的上传地址是 ${OSS_UPLOAD_PATH_PARAM}获取到的assets-oss-endpoint是 ${ASSETS_END_POINT_PARAM}"
} catch (err) {
def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Debug】【${CHANNEL_PARAM}】根据渠道获取相关参数失败"
SendMessageToWechat(message)
error("Failure of the '根据渠道获取相关参数' stage")
}
}
}
}
@ -234,6 +262,12 @@ pipeline {
sh "chmod +x $WORKSPACE/Tool/build_tools/debug_send_version.sh"
def result=0
result = sh(script: "$WORKSPACE/Tool/build_tools/debug_send_version.sh")
if(result != 0)
{
def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Debug】【${CHANNEL_PARAM}】发布debug版本号失败"
SendMessageToWechat(message)
error("Failure of the '发布debug版本号' stage")
}
}
}
}

View File

@ -10,20 +10,29 @@ def CHANNEL_PARAM = params.Channel
def DEBUGBUILD_PARAM = params.DebugBuild
def HOTUPDATE_PARAM = params.Enable_Hot_Update
//
def VERSION_PARAM
// Jenkins
def ARTIFACT_URL = "http://${env.PHXH_BUILDER_IP_ADDRESS}:8080/job/${env.JOB_NAME}/"
def VERSION_PARAM //
def OSS_UPLOAD_PATH_PARAM //
def ASSETS_END_POINT_PARAM // Assets endPoint
//
def BUILD_PATH
//
def log_path
// Jenkins
def ARTIFACT_URL = "http://${env.PHXH_BUILDER_IP_ADDRESS}:8080/job/${env.JOB_NAME}/"
// xcode
def PROJECT_NAME = "Unity-iPhone"
def SCHEME_NAME = "Unity-iPhone"
def GetRemote(){
/*if('BilibiliDev' == params.Channel)
return 'bilibili';
else*/
return 'main';
}
def SendMessageToWechat(message){
if (!message) {
return }
@ -56,54 +65,106 @@ pipeline {
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"
}
try {
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"
}
// 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']]
)
checkout scmGit(branches: [[name: '*/main']],
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']])
// 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 = GetRemote();
sh "chmod +x ${WORKSPACE}/Tool/build_tools/git_pull_gameplay.sh"
sh "$WORKSPACE/Tool/build_tools/git_pull_gameplay.sh ${gameplayTargetPath} ${gameplayPath} ${branch}"
} catch (err) {
def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Debug】【${CHANNEL_PARAM}】拉最新工程失败"
SendMessageToWechat(message)
error("Failure of the '拉最新工程' stage")
}
}
}
}
stage('获取项目配置') {
steps {
//
sh "chmod +x $WORKSPACE/Tool/build_tools/copy_env.sh"
sh "$WORKSPACE/Tool/build_tools/copy_env.sh $WORKSPACE/Tool/build_env"
script {
try {
//
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/"
//
echo "copy local env file to $WORKSPACE"
sh "cp /Users/mayuanzheng/Builds/local_env.sh $WORKSPACE/Tool/build_tools/"
} catch (err) {
def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Debug】【${CHANNEL_PARAM}】获取项目配置失败"
SendMessageToWechat(message)
error("Failure of the '获取项目配置' stage")
}
}
}
}
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}"
script {
try {
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}"
} catch (err) {
def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Debug】【${CHANNEL_PARAM}】根据渠道修改工程失败"
SendMessageToWechat(message)
error("Failure of the '根据渠道修改工程' stage")
}
}
}
}
stage('获取打包版本') {
stage('根据渠道获取相关参数') {
steps {
script {
echo "获取 [${params.Channel}] 渠道版本"
def playersettings = "$WORKSPACE/Tool/Channels/$CHANNEL_PARAM/ChannelSetting.txt"
sh "chmod +x $WORKSPACE/Tool/build_tools/get_build_version.sh"
VERSION_PARAM = sh(script: "$WORKSPACE/Tool/build_tools/get_build_version.sh $playersettings", returnStdout: true).trim()
BUILD_PATH = "Builds/$CHANNEL_PARAM/$PLATFORM_PARAM/$VERSION_PARAM"
log_path="$BUILD_PATH/build.log"
echo "获取到的版本是 $VERSION_PARAM"
try {
echo "根据 [${params.Channel}] 渠道获取相关参数"
def playersettings = "$WORKSPACE/Tool/Channels/$CHANNEL_PARAM/ChannelSetting.txt"
sh "chmod +x $WORKSPACE/Tool/build_tools/get_build_version.sh"
sh "chmod +x $WORKSPACE/Tool/build_tools/get_build_upload_path.sh"
sh "chmod +x $WORKSPACE/Tool/build_tools/get_build_assets_end_point.sh"
VERSION_PARAM = sh(script: "$WORKSPACE/Tool/build_tools/get_build_version.sh $playersettings", returnStdout: true).trim()
OSS_UPLOAD_PATH_PARAM = sh(script: "$WORKSPACE/Tool/build_tools/get_build_upload_path.sh $playersettings", returnStdout: true).trim()
ASSETS_END_POINT_PARAM = sh(script: "$WORKSPACE/Tool/build_tools/get_build_assets_end_point.sh $playersettings", returnStdout: true).trim()
BUILD_PATH = "Builds/$CHANNEL_PARAM/$PLATFORM_PARAM/$VERSION_PARAM"
log_path="$BUILD_PATH/build.log"
echo "获取到的版本是 ${VERSION_PARAM}, 获取到的上传地址是 ${OSS_UPLOAD_PATH_PARAM}获取到的assets-oss-endpoint是 ${ASSETS_END_POINT_PARAM}"
} catch (err) {
def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Debug】【${CHANNEL_PARAM}】根据渠道获取相关参数失败"
SendMessageToWechat(message)
error("Failure of the '根据渠道获取相关参数' stage")
}
}
}
}
@ -142,16 +203,12 @@ pipeline {
stage('上传资源') {
steps {
script {
sh "chmod +x $WORKSPACE/Tool/build_tools/upload_oss_dev.sh"
sh "chmod +x $WORKSPACE/Tool/build_tools/upload_oss.sh"
def asset_path="$WORKSPACE/ProjectNLD/ServerData/${PLATFORM_PARAM}"
def upload_path="${CHANNEL_PARAM}/${PLATFORM_PARAM}/${VERSION_PARAM}"
def upload_path="${OSS_UPLOAD_PATH_PARAM}/${CHANNEL_PARAM}/${PLATFORM_PARAM}/${VERSION_PARAM}"
def upload_result=0
if(DEV_PARAM)
upload_result=sh(script: "$WORKSPACE/Tool/build_tools/upload_oss_dev.sh ${asset_path} ${upload_path}", returnStatus: true, returnStdout: false)
else
upload_result=sh(script: "$WORKSPACE/Tool/build_tools/upload_oss.sh ${asset_path} ${upload_path}", returnStatus: true, returnStdout: false)
upload_result = sh(script: "$WORKSPACE/Tool/build_tools/upload_oss.sh ${asset_path} ${upload_path} ${ASSETS_END_POINT_PARAM}", returnStatus: true, returnStdout: false)
if(upload_result != 0)
{
@ -167,8 +224,15 @@ pipeline {
script {
if (params.Build_InitApp == true) {
def project_path="$WORKSPACE/Builds/$CHANNEL_PARAM/$PLATFORM_PARAM/$VERSION_PARAM"
def export_result=0
sh "chmod +x $WORKSPACE/Tool/build_tools/build_xcode_xcodeproj.sh"
sh "$WORKSPACE/Tool/build_tools/build_xcode_xcodeproj.sh ${PROJECT_NAME} ${SCHEME_NAME} ${project_path}"
export_result = sh(script: "$WORKSPACE/Tool/build_tools/build_xcode_xcodeproj.sh ${PROJECT_NAME} ${SCHEME_NAME} ${project_path}", returnStatus: true, returnStdout: false)
if(export_result != 0)
{
def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Debug】【${CHANNEL_PARAM}】导出IPA失败"
SendMessageToWechat(message)
error("Failure of the '导出IPA' stage")
}
}
}
}
@ -177,9 +241,16 @@ pipeline {
steps {
script {
if (params.Build_InitApp == true) {
def change_name_result=0
def path="$WORKSPACE/Builds/$CHANNEL_PARAM/$PLATFORM_PARAM/$VERSION_PARAM/"
sh "chmod +x $WORKSPACE/Tool/build_tools/rename_ipa.sh"
sh "$WORKSPACE/Tool/build_tools/rename_ipa.sh ${path}"
change_name_result = sh(script: "$WORKSPACE/Tool/build_tools/rename_ipa.sh ${path}", returnStatus: true, returnStdout: false)
if(change_name_result != 0)
{
def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Debug】【${CHANNEL_PARAM}】重命名IPA失败"
SendMessageToWechat(message)
error("Failure of the '重命名IPA' stage")
}
}
}
}
@ -190,32 +261,39 @@ pipeline {
//
if (params.Build_InitApp == true){
def ipa_path="$WORKSPACE/Builds/$CHANNEL_PARAM/$PLATFORM_PARAM/$VERSION_PARAM/$IPA_NAME"
def upload_path="${CHANNEL_PARAM}/${PLATFORM_PARAM}"
def upload_path_with_version="${CHANNEL_PARAM}/${PLATFORM_PARAM}/${VERSION_PARAM}"
def upload_path="${OSS_UPLOAD_PATH_PARAM}/${CHANNEL_PARAM}/${PLATFORM_PARAM}/"
def upload_path_with_version="${OSS_UPLOAD_PATH_PARAM}/${CHANNEL_PARAM}/${PLATFORM_PARAM}/${VERSION_PARAM}/"
def upload_result=0
def upload_result_with_version=0
if(DEV_PARAM)
{
upload_result=sh(script: "$WORKSPACE/Tool/build_tools/upload_oss_dev.sh ${ipa_path} ${upload_path}", returnStatus: true, returnStdout: false)
upload_result_with_version=sh(script: "$WORKSPACE/Tool/build_tools/upload_oss_dev.sh ${ipa_path} ${upload_path_with_version}", returnStatus: true, returnStdout: false)
}
else
{
upload_result=sh(script: "$WORKSPACE/Tool/build_tools/upload_oss.sh ${ipa_path} ${upload_path}", returnStatus: true, returnStdout: false)
upload_result_with_version=sh(script: "$WORKSPACE/Tool/build_tools/upload_oss.sh ${ipa_path} ${upload_path_with_version}", returnStatus: true, returnStdout: false)
}
upload_result=sh(script: "$WORKSPACE/Tool/build_tools/upload_oss.sh ${ipa_path} ${upload_path} ${ASSETS_END_POINT_PARAM}", returnStatus: true, returnStdout: false)
upload_result_with_version=sh(script: "$WORKSPACE/Tool/build_tools/upload_oss.sh ${ipa_path} ${upload_path_with_version} ${ASSETS_END_POINT_PARAM}", returnStatus: true, returnStdout: false)
if(upload_result != 0 || upload_result_with_version != 0)
{
def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Debug】【${CHANNEL_PARAM}】上传IPA失败"
SendMessageToWechat(message)
error("Failure of the '上传ipa' stage")
error("Failure of the '上传IPA' stage")
}
}
}
}
}
stage('发布debug版本号') {
steps {
script {
sh "chmod +x $WORKSPACE/Tool/build_tools/debug_send_version.sh"
def result=0
//result = sh(script: "$WORKSPACE/Tool/build_tools/debug_send_version.sh")
if(result != 0)
{
def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【Debug】【${CHANNEL_PARAM}】发布debug版本号失败"
SendMessageToWechat(message)
error("Failure of the '发布debug版本号' stage")
}
}
}
}
stage('归档') {
steps {
script {