import groovy.json.JsonSlurperClassic pipeline { agent{ label 'superMac' // customWorkspace 'D:/Jenkins/workspace/test' } environment { u2china_share_proj = '${WORKSPACE}/u2china_share_proj' //serverPath = '${WORKSPACE}/u2china_svr_proj' branch = "${BranchName}" // trunk , branch svn = "/usr/local/bin/svn" unityApp="/Applications/Unity/Hub/Editor/2019.4.40f1/Unity.app/Contents/MacOS/Unity" u2china_cli_proj = "${WORKSPACE}/u2china_cli_proj" u2china_pro_dir= "${u2china_cli_proj}/arpg" build_graph="Assets/ZXToolkit/AssetGraph/Graph/BuildGraph.asset" output_dir="${WORKSPACE}/outputBuild/android" log_dir="${WORKSPACE}/log/android" disableLog="false" lang="en" gameIP="123.60.58.245" maintenanceIP="123.60.58.245" versionIP="123.60.58.245" buildmode = "apk" publishChannel = "none" } stages { stage("svn share_proj"){ steps{ sh label: '', script: """ chmod 774 ${WORKSPACE}/CheckoutShare.py python3 ${WORKSPACE}/CheckoutShare.py ${env.branch} "share" """ } } stage("svn client_proj"){ steps{ sh label: '', script: """ chmod 774 ${WORKSPACE}/CheckoutShare.py python3 ${WORKSPACE}/CheckoutShare.py ${env.branch} "client" """ } } stage("Set AppVersion"){ steps{ sh label: '', script: """ chmod 774 ${env.u2china_share_proj}/MacBuild/modifyVersion.py python3 ${env.u2china_share_proj}/MacBuild/modifyVersion.py autoCommit """ } } stage("Set BuildParams"){ steps{ sh label: '', script: """ cd ${u2china_cli_proj} python3 ${u2china_cli_proj}/../u2china_share_proj/MacBuild/build_generate_common.py debug=$OpenDebug version="-1" disableLog=$disableLog versionIP="${versionIP}" mode=$buildmode publishChannel=$publishChannel gameIP=$gameIP maintenanceIP=$maintenanceIP lang=$lang """ } } stage("BuildAPK"){ steps{ script { json_file = "${env.u2china_pro_dir}/Assets/buildVersion.json" json_contents = readFile json_file def dataObject = new JsonSlurperClassic().parseText(json_contents) appVersion = "${dataObject.appVersion}" println "${dataObject.appVersion}" buid_name="u2china_${appVersion}" build_file_name="${buid_name}.apk" outpath="${output_dir}/${build_file_name}" } sh label: '', script:""" ${unityApp} -quit -batchmode -projectPath ${u2china_pro_dir} -logFile ${log_dir}/${buid_name}.log -executeMethod XAsset.Build.AssetBuildScript.RunBuild version=${appVersion} outpath=${outpath} development=${development} versionIP=${versionIP} mode=${buildmode} publishChannel=${publishChannel} graph=${build_graph} target=${targetPlatform} rebuildBundle=${BuildAssetbundle} """ } } stage("copy apk"){ steps{ sh label: '', script: """ if [ ! -f ${outpath} ]; then echo "文件不存在" exit 1 fi cp ${outpath} /Volumes/Disk2/download/DownloadAPk/${build_file_name} """ } } } post { success { wrap([$class: 'BuildUser']) { script { buildUser = "${env.BUILD_USER}" } buildName "#${env.BUILD_NUMBER} ---> ${appVersion}" buildDescription "点击下载: u2china_${appVersion}" } sh label: '', script: """sh ${env.u2china_share_proj}/JenkinsFile/feishu_buildPackage.sh ${buildUser} ${appVersion} SUCCESS ${env.JOB_NAME} apk""" } failure { wrap([$class: 'BuildUser']) { script { buildUser = "${env.BUILD_USER}" } } sh label: '', script: """sh ${env.u2china_share_proj}/JenkinsFile/feishu_buildPackage.sh ${buildUser} ${appVersion} FAILURE ${env.JOB_NAME} apk""" echo "FAILURE" } } }