def VERSION_PARAM = params.VERSION def PROFILE_PARAM = "Debug" def PLATFORM_PARAM = "Android" def ARTIFACT_URL = "http://192.168.2.159:8080/job/${env.JOB_NAME}/" def Enable_Hot_Update = "false" def BUILD_PATH = "Builds/$PLATFORM_PARAM/$VERSION_PARAM" def build_result def checkFolderExists(folderPath) { def combieCmd = "test -d ${folderPath} && echo exists || echo not exists" def folderExists = sh(script: combieCmd, returnStdout: true).trim() if (folderExists == 'exists') { return true; } else { return false; } } def checkFileExists(filePath) { def combieCmd = "test -f ${filePath} && echo exists || echo not exists" def fileExists = sh(script: combieCmd, returnStdout: true).trim() if (fileExists == 'exists') { return true; } else { return false; } } def copyFolder(sourceFolder, targetFolder) { sh "cp -Rf ${sourceFolder} ${targetFolder}" } def copyFile(sourceFile, targetFile) { sh "cp -f ${sourceFile} ${targetFile}" } pipeline { agent any stages { stage('拉最新工程') { steps { //echo 'p4 拉取最新的代码....' //checkout perforce( //credential: 'af66652c-5a02-4d8c-9727-9955d855d23f', //populate: autoClean(delete: true, modtime: false, //parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], //pin: '', quiet: true, replace: true, tidy: false), //workspace: streamSpec(charset: 'utf8', format: 'jenkins-${NODE_NAME}-${JOB_NAME}-${EXECUTOR_NUMBER}', pinHost: false, streamName: '//ProjectNLD/main') //) echo 'git 还原本地修改....' script { // 保存当前工作路径 def currentPath = sh(script: 'pwd', returnStdout: true).trim() echo "Current path: ${currentPath}" // 先删除Assets/PhxhSDK/Phxh/SDKHelper文件夹 def sdkHelperPath = "$WORKSPACE/ProjectNLD/Assets/PhxhSDK/Phxh/SDKHelper" if (checkFolderExists(sdkHelperPath)) { echo "准备删除${sdkHelperPath}文件夹" sh "rm -rf ${sdkHelperPath}" echo "删除${sdkHelperPath}文件夹成功" } // cd到Phxh目录并进行还原 echo "cd $WORKSPACE/ProjectNLD/Assets/PhxhSDK/Phxh" sh "cd $WORKSPACE/ProjectNLD/Assets/PhxhSDK/Phxh && git checkout -- ." // def projectSettingsPath = "$WORKSPACE/ProjectNLD/ProjectSettings" // if (checkFolderExists(projectSettingsPath)) { // echo "准备删除${projectSettingsPath}文件夹" // sh "rm -rf ${projectSettingsPath}" // echo "删除${projectSettingsPath}文件夹成功" // } // // cd到ProjectSettings目录并进行还原 // echo "cd $WORKSPACE/ProjectNLD/ProjectSettings" // sh "cd $WORKSPACE/ProjectNLD/ProjectSettings && git checkout -- ." // cd到工作路径 echo "cd ${currentPath}" } echo 'git 拉取最新的代码....' checkout scmGit(branches: [[name: '*/main']], extensions: [checkoutOption(60), lfs(), submodule(recursiveSubmodules: true, reference: '', timeout: 1200)], userRemoteConfigs: [[url: 'http://1.14.122.170:3000/PHXH/NLDClient.git']]) } } stage('根据channel拷贝文件') { steps { script { echo "根据channel拷贝文件" // 先判定channel文件夹是否存在 def channelPath = "$WORKSPACE/Tool/Channels/${params.Channel}" if (!checkFolderExists(channelPath)) { error("Channel文件夹不存在: ${channelPath}") } // 判断define_list.txt文件是否存在 def defineListPath = "${channelPath}/define_list.txt" if (!checkFileExists(defineListPath)) { error("define_list.txt文件不存在: ${defineListPath}") } // 拷贝Asset文件夹 def channelAssetPath = "${channelPath}/Assets" if (checkFolderExists(channelAssetPath)) { copyFolder(channelAssetPath, "$WORKSPACE/ProjectNLD/") echo "拷贝Asset文件夹成功" } // 拷贝ProjectSettings文件夹 def channelProjectSettingsPath = "${channelPath}/ProjectSettings" if (checkFolderExists(channelProjectSettingsPath)) { copyFolder(channelProjectSettingsPath, "$WORKSPACE/ProjectNLD/") echo "拷贝ProjectSettings文件夹成功" } // 拷贝define_list.txt文件 copyFile(defineListPath, "$WORKSPACE/ProjectNLD/define_list.txt") echo "拷贝define_list.txt文件成功" } } } stage('打包') { steps { echo "copy local env file to ${WORKSPACE}" sh "cp /Users/mayuanzheng/Builds/local_env.sh $WORKSPACE/Tool/BuildTool/" echo "make shell executable" sh "chmod +x $WORKSPACE/Tool/BuildTool/build_android_debug.sh" sh "chmod +x $WORKSPACE/Tool/BuildTool/update_build_resource_android_debug.sh" echo "execute build shell" script { if(params.Debug_AllLocal == true) PROFILE_PARAM="AllLocal" if(params.Enable_Hot_Update == true) Enable_Hot_Update = "true" if(params.Update_Previous_Build == true) build_result=sh(script: "$WORKSPACE/Tool/BuildTool/update_build_resource_android_debug.sh ${VERSION_PARAM} ${PLATFORM_PARAM} ${PROFILE_PARAM} ${ARTIFACT_URL} ${Enable_Hot_Update}", returnStatus: true, returnStdout: false) else build_result=sh(script: "$WORKSPACE/Tool/BuildTool/build_android_debug.sh ${VERSION_PARAM} ${PROFILE_PARAM} ${ARTIFACT_URL} ${Enable_Hot_Update}", returnStatus: true, returnStdout: false) if(build_result != 0) { archiveArtifacts artifacts: "$BUILD_PATH/build.log" , followSymlinks: false error("Failure of the '打包' stage") } } } } stage('上传') { steps { echo "上传" echo "make shell executable" sh "chmod +x $WORKSPACE/Tool/BuildTool/upload_to_server.sh" echo "execute build shell" sh "$WORKSPACE/Tool/BuildTool/upload_to_server.sh ${VERSION_PARAM} ${PLATFORM_PARAM}" } } stage('归档') { steps { echo "归档" script { if (params.Update_Previous_Build == false) { archiveArtifacts artifacts: "$BUILD_PATH/*.apk" , followSymlinks: false archiveArtifacts artifacts: "$BUILD_PATH/build.log" , followSymlinks: false } else { archiveArtifacts artifacts: "$BUILD_PATH/UpdatePreviousBuild.log" , followSymlinks: false } } } } stage('通知') { steps { echo "通知" sh "chmod +x $WORKSPACE/Tool/BuildTool/to_wechat_robot.sh" script { def message = "【${PLATFORM_PARAM}】【${VERSION_PARAM}】【${PROFILE_PARAM}】客户端打包上传成功!下载链接:${ARTIFACT_URL}" sh "$WORKSPACE/Tool/BuildTool/to_wechat_robot.sh ${message}" } } } } }