1.一键打ab包,包括拉项目,打包,上传ftp
#!/bin/bash echo "---------------------------------------------->Invoke BuildAB.sh<----------------------------------------------" pwd m_UnityPath=${1} m_ProjFolder=${2} m_Platform=${3} m_ForceRebuild=${4} m_FtpUrl=${5} m_FtpDir=${6} m_CdnUrl=${7} m_FtpRSA=${8} m_FtpPort=${9} m_FtpUser=${10} # 项目拉到最新 if [ $m_UpdateMain = "true" ];then echo "---------------------------------------------->Update main project<----------------------------------------------" cd $m_ProjFolder git checkout .;git clean -fd;git pull;git log -1 fi if [ $m_UpdateArt = "true" ];then echo "---------------------------------------------->Update art project<----------------------------------------------" cd $m_ProjFolder/UnityClient/Assets/FashionBeat_ArtSVN svn cleanup;svn revert --recursive .;svn update;svn log -l 1 fi if [ $m_UpdateMusic = "true" ];then echo "---------------------------------------------->Update music project<----------------------------------------------" cd $m_ProjFolder/UnityClient/Assets/FashionBeat_MusicGit git checkout .;git clean -fd;git pull;git log -1 fi if [ $m_ConvertConfig = "true" ];then echo "---------------------------------------------->Update excel config<----------------------------------------------" cd $m_ProjFolder/../server svn cleanup;svn revert --recursive .;svn update;svn log -l 1 fi # Unity打包 if [ $m_ConvertConfig = "true" -o $m_BuildAB = "true" ];then echo "---------------------------------------------->Unity, JenkinsTool.BuildAB<----------------------------------------------" echo "m_UnityPath:$m_UnityPath" "$m_UnityPath" -projectPath "$m_ProjFolder/UnityClient" \ -buildTarget $m_Platform \ -logFile "${WORKSPACE}/Publish/log/log_BuildAB.txt" \ -executeMethod JenkinsTool.BuildAB \ -quit -batchmode -nographics \ -buildParams \ "m_ConvertConfig=$m_ConvertConfig" \ "m_BuildAB=$m_BuildAB" \ "m_CopyABToStream=$m_CopyABToStream" \ "m_BuildTarget=$m_Platform" \ "m_ForceRebuild=$m_ForceRebuild" \ || exit 1 cd $m_ProjFolder git add "UnityClient/Assets/Config/Tbl";git add "UnityClient/Assets/Scripts/XLua/LuaScripts/Config" #if [ $m_Platform = "iOS" -a $m_CopyABToStream = "true" ];then # git add "UnityClient/Assets/StreamingAssets"; #fi git pull;git commit -m "Jenkins: 上传打包结果";git push;git show head --stat echo "Unity build succeed" fi # Ftp上传 if [ $m_UploadFtp = "true" ];then echo "---------------------------------------------->Rsync ab to ftp<----------------------------------------------" cd ${m_ProjFolder} ssh -i ${JenkinsCode}/rsa/${m_FtpRSA} -p ${m_FtpPort} ${m_FtpUser}@${m_FtpUrl} "mkdir -p ${m_CdnUrl}/${m_FtpDir}/" rsync -arze "ssh -i ${JenkinsCode}/rsa/${m_FtpRSA} -p ${m_FtpPort}" --progress "UnityClient/a/" ${m_FtpUser}@${m_FtpUrl}:${m_CdnUrl}/${m_FtpDir}/ echo "Upload to ftp succeed" fi echo "---------------------------------------------->BuildAB.sh invoked finished!<----------------------------------------------"
2.一键导出项目
#!/bin/bash echo "---------------------------------------------->Invoke BuildApkExportProj.sh<----------------------------------------------" pwd m_UnityPath=${1} m_ProjFolder=${2} m_Platform=${3} m_ExportPath="${WORKSPACE}/Publish/export/UnityExportProject/buildplayer" # 杀unity进程 if [ $m_KillUnity = "true" ];then echo "---------------------------------------------->Kill Unity.exe<----------------------------------------------" ${JenkinsCode}/KillUnity.bat fi # 清理XLua code if [ $m_ClearLua = "true" -o $m_GenerateLua = "true" ];then echo "---------------------------------------------->Clear lua code<----------------------------------------------" luaGenFolder="${m_ProjFolder}/UnityClient/Assets/ThirdParty/XLua/Gen" rm -rf $luaGenFolder echo "Delete folder:"${luaGenFolder} fi # 项目拉到最新 if [ $m_UpdateMain = "true" ];then echo "---------------------------------------------->Update main project<----------------------------------------------" cd $m_ProjFolder git checkout .;git clean -fd;git pull;git log -1 fi # Unity打包 if [ $m_BuildPlayer = "true" ];then echo "---------------------------------------------->Unity, JenkinsTool.BuildPlayer<----------------------------------------------" rm -rf $m_ExportPath echo "Delete folder:"${m_ExportPath} "$m_UnityPath" -projectPath "$m_ProjFolder/UnityClient" \ -buildTarget $m_Platform \ -logFile "${WORKSPACE}/Publish/log/log_BuildApkExportProj.txt" \ -executeMethod JenkinsTool.BuildPlayer \ -quit -batchmode -nographics \ -buildParams \ "m_ExportPath=$m_ExportPath" \ "m_GenerateLua=$m_GenerateLua" \ || exit 1 echo "Unity build player finished:${m_ExportPath}" fi # 压缩 if [ $m_ZipFiles = "true" ];then echo "---------------------------------------------->Zip export files<----------------------------------------------" zipPath="${WORKSPACE}/Publish/export/BuildApkExportProj.zip" cd "$m_ExportPath" rm -rf "${zipPath}" zip -r "${zipPath}" ./* echo "Zip finished:${zipPath}" fi echo "---------------------------------------------->BuildApkExportProj.sh invoked finished!<----------------------------------------------"
3.一键出不带sdk的apk
#!/bin/bash echo "---------------------------------------------->Invoke BuildApkNoSDK.sh<----------------------------------------------" pwd m_UnityPath=${1} m_ProjFolder=${2} m_Platform=${3} m_ExportPath="${WORKSPACE}/Publish/export/no_sdk.apk" # 杀unity进程 if [ $m_KillUnity = "true" ];then echo "---------------------------------------------->Kill Unity.exe<----------------------------------------------" ${JenkinsCode}/KillUnity.bat fi # 清理XLua code if [ $m_ClearLua = "true" -o $m_GenerateLua = "true" ];then echo "---------------------------------------------->Clear lua code<----------------------------------------------" luaGenFolder="${m_ProjFolder}/UnityClient/Assets/ThirdParty/XLua/Gen" rm -rf $luaGenFolder echo "Delete folder:"${luaGenFolder} fi # 项目拉到最新 if [ $m_UpdateMain = "true" ];then echo "---------------------------------------------->Update main project<----------------------------------------------" cd $m_ProjFolder git checkout .;git clean -fd;git pull;git log -1 fi # Unity打包 if [ $m_BuildPlayer = "true" ];then echo "---------------------------------------------->Unity, JenkinsTool.BuildAPK<----------------------------------------------" rm -rf $m_ExportPath echo "Delete:"${m_ExportPath} "$m_UnityPath" -projectPath "$m_ProjFolder/UnityClient" \ -buildTarget $m_Platform \ -logFile "${WORKSPACE}/Publish/log/log_BuildApkNoSDK.txt" \ -executeMethod JenkinsTool.BuildAPK \ -quit -batchmode -nographics \ -buildParams \ "m_ExportPath=$m_ExportPath" \ "m_GenerateLua=$m_GenerateLua" \ || exit 1 echo "Unity build player finished" fi echo "---------------------------------------------->BuildApkNoSDK.sh invoked finished!<----------------------------------------------"
4.一键出带sdk的apk
#!/bin/bash echo "---------------------------------------------->Invoke BuildApkWithSDK.sh<----------------------------------------------" pwd m_UnityPath=${1} m_ProjFolder=${2} m_Platform=${3} m_ProductCode=${4} # 杀unity进程 if [ $m_KillUnity = "true" ];then echo "---------------------------------------------->Kill Unity.exe<----------------------------------------------" ${JenkinsCode}/KillUnity.bat fi # 清理XLua code if [ $m_ClearLua = "true" -o $m_GenerateLua = "true" ];then echo "---------------------------------------------->Clear lua code<----------------------------------------------" luaGenFolder="${m_ProjFolder}/UnityClient/Assets/ThirdParty/XLua/Gen" rm -rf $luaGenFolder echo "Delete folder:"${luaGenFolder} fi # 项目拉到最新 if [ $m_UpdateMain = "true" ];then echo "---------------------------------------------->Update main project<----------------------------------------------" cd $m_ProjFolder git checkout .;git clean -fd;git pull;git log -1 fi # SDK项目拉到最新 if [ $m_UpdateSDKProj = "true" ];then echo "---------------------------------------------->Update sdk project<----------------------------------------------" cd $SDKCode git checkout .;git clean -fd;git pull;git log -1 fi # Unity导出 if [ $m_ExportUnityProj = "true" ];then echo "---------------------------------------------->Unity, JenkinsTool.BuildPlayer<----------------------------------------------" exportPath="${SDKCode}/../u2as" rm -rf $exportPath echo "Delete folder:"${exportPath} "$m_UnityPath" -projectPath "$m_ProjFolder/UnityClient" \ -buildTarget $m_Platform \ -logFile "${WORKSPACE}/Publish/log/log_BuildApkWithSDK.txt" \ -executeMethod JenkinsTool.BuildPlayer \ -quit -batchmode -nographics \ -buildParams \ "m_ExportPath=$exportPath" \ "m_GenerateLua=$m_GenerateLua" \ || exit 1 echo "Unity build player finished:${exportPath}" fi # 集成sdk if [ $m_BuildSDK = "true" ];then echo "---------------------------------------------->Build apk with sdk<----------------------------------------------" cd $SDKCode curTime=`date +%Y%m%d_%H%M%S` m_ApkName="${m_Region,,}_${curTime}.${m_TargetType,,}" echo "apk name: ${m_ApkName}" python -u "Python_script/jekinsgames.py" \ "${m_ProductCode}" \ "${m_Region}" \ "${m_VersionAddress}" \ "${m_TargetType}" \ "${m_SplitPackage}" \ "${m_VersionName}" \ "${m_VersionCode}" \ "${m_ApkName}" fi # 将apk移到Jenkins目录 cd "${SDKCode}/../apk" tarFolder="${WORKSPACE}/Publish/export" mkdir -p "${tarFolder}" mv *.apk "${tarFolder}" echo "---------------------------------------------->BuildApkWithSDK.sh invoked finished!<----------------------------------------------"
5.导出本地化翻译
#!/bin/bash echo "---------------------------------------------->Invoke ExportLocFile.sh<----------------------------------------------" pwd m_UnityPath=${1} m_ProjFolder=${2} m_Platform=${3} m_Language=${4} # 项目拉到最新 if [ $m_GetChinese = "true" ];then echo "---------------------------------------------->Update excel config<----------------------------------------------" cd $m_ProjFolder/../server svn cleanup;svn revert --recursive .;svn update;svn log -l 1 fi echo "---------------------------------------------->Update main project<----------------------------------------------" cd $m_ProjFolder git checkout .;git clean -fd;git pull;git log -1 # Unity打包 echo "---------------------------------------------->Unity, JenkinsTool.ExportLoc<----------------------------------------------" "$m_UnityPath" -projectPath "$m_ProjFolder/UnityClient" \ -buildTarget $m_Platform \ -logFile "${WORKSPACE}/Publish/log/log_ExportLocFile.txt" \ -executeMethod JenkinsTool.ExportLoc \ -quit -batchmode -nographics \ -buildParams \ "m_GetChinese=$m_GetChinese" \ "m_ExportPath=${WORKSPACE}/Publish/loc" \ "m_Language=$m_Language" \ || exit 1 echo "Unity build player finished." #上传 cd $m_ProjFolder git add "UnityClient/Assets/Localize/Text";git pull;git commit -m "Jenkins: 从配置和静态UI中提取本地化";git push;git show head echo "---------------------------------------------->ExportLocFile.sh invoked finished!<----------------------------------------------"
6.导入本地化翻译
#!/bin/bash echo "---------------------------------------------->Invoke ImportLocFile.sh<----------------------------------------------" pwd m_UnityPath=${1} m_ProjFolder=${2} m_Platform=${3} m_Language=${4} # 项目拉到最新 echo "---------------------------------------------->Update main project<----------------------------------------------" cd $m_ProjFolder git checkout .;git clean -fd;git pull;git log -1 # Unity打包 echo "---------------------------------------------->Unity,JenkinsTool.ImportLoc<----------------------------------------------" "$m_UnityPath" -projectPath "$m_ProjFolder/UnityClient" \ -buildTarget $m_Platform \ -logFile "${WORKSPACE}/Publish/log/log_ImportLocFile.txt" \ -executeMethod JenkinsTool.ImportLoc \ -quit -batchmode -nographics \ -buildParams \ "m_LocalizedExcel=${WORKSPACE}/m_LocalizedExcel" \ "m_Language=$m_Language" \ || exit 1 echo "Unity import localize file finished." #上传 cd $m_ProjFolder git add "UnityClient/Assets/Localize/Text";git add "UnityClient/Assets/Resources/FashionBeat/Localize";git pull;git commit -m "Jenkins: 导入已翻译的本地化文件";git push;git show head echo "---------------------------------------------->ImportLocFile.sh invoked finished!<----------------------------------------------"
7.杀unity进程bat
::tasklist | findstr Unity* taskkill /f /im Unity*
8.放在unity中的cs代码
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Text; using CSObjectWrapEditor; using UnityEditor; using UnityEngine; using YooAsset.Editor; public class JenkinsTool : ScriptableObject { static string[] BuildingScenes { get { List<string> scenes = new List<string>(); foreach (EditorBuildSettingsScene scene in EditorBuildSettings.scenes) { if (scene != null && scene.enabled) scenes.Add(scene.path); } return scenes.ToArray(); } } public static string GetArg(string name, string defaultArg) { if (string.IsNullOrEmpty(name)) return defaultArg; string[] args = Environment.GetCommandLineArgs(); string argStart = string.Format("{0}=", name); foreach (string arg in args) { if (arg.StartsWith(argStart)) { string argFixed = arg.Substring(argStart.Length); return string.IsNullOrEmpty(argFixed) ? defaultArg : argFixed; } } return defaultArg; } public static void BuildAB() { bool convertConfig = GetArg("m_ConvertConfig", "false") == "true"; bool buildAB = GetArg("m_BuildAB", "false") == "true"; string strBuildTarget = GetArg("m_BuildTarget", "Android"); BuildTarget buildTarget = (BuildTarget)Enum.Parse(typeof(BuildTarget), strBuildTarget); if (convertConfig) ConvertConfig(); if (buildAB) YooAssetBuild(buildTarget); Debug.Log("#Jenkins, JenkinsTool.BuildAB() finished! "); } [MenuItem("FashionBeat/Jenkins/ConvertConfig")] static void ConvertConfig() { ConfigConverter.JenkinsConvertConfig(); Debug.Log("#Jenkins, ConfigConverter.ConvertAllConfig() finished! "); } static void YooAssetBuild(BuildTarget buildTarget) { Debug.Log($"#Jenkins, Yoo asset 开始构建 : {buildTarget}"); bool forceRebuild = GetArg("m_ForceRebuild", "false") == "true"; var buildMode = forceRebuild ? EBuildMode.ForceRebuild : EBuildMode.IncrementalBuild; bool copyAB = GetArg("m_CopyABToStream", "false") == "true"; ECopyBuildinFileOption copyOption = copyAB ? ECopyBuildinFileOption.ClearAndCopyByTags : ECopyBuildinFileOption.None; string copyTags = copyAB ? "local;" : ""; Debug.Log("m_ForceRebuild=" + forceRebuild); Debug.Log("m_CopyABToStream=" + copyAB); // 构建参数 BuildParameters p = new BuildParameters() { OutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot(), BuildTarget = buildTarget, BuildPipeline = EBuildPipeline.BuiltinBuildPipeline, BuildMode = buildMode, BuildPackage = "DefaultPackage", HumanReadableVersion = "a", VerifyBuildingResult = true, EnableAddressable = true, EncryptionServices = null, OutputNameStyle = EOutputNameStyle.HashName, CopyBuildinFileOption = copyOption, CopyBuildinFileTags = copyTags, CompressOption = ECompressOption.LZ4, }; // 执行构建 AssetBundleBuilder builder = new AssetBundleBuilder(); var buildResult = builder.Run(p); if (copyAB) { YooAssetTool.CopyBundleToStream(); } Debug.Log($"#Jenkins, ConfigConverter.YooBuildInternal() finished,result {buildResult.Success}"); } [MenuItem("FashionBeat/Jenkins/BuildPlayer")] public static void BuildPlayer() { bool generateLua = GetArg("m_GenerateLua", "false") == "true"; if (generateLua) { Generator.ClearAll(); Generator.GenAll(); } string path = GetArg("m_ExportPath", ""); if (string.IsNullOrEmpty(path)) { path = "../../export"; } if (Directory.Exists(path)) { Directory.Delete(path, true); } BuildTarget target = BuildTarget.Android; BuildOptions options = BuildOptions.None; EditorUserBuildSettings.exportAsGoogleAndroidProject = true; EditorUserBuildSettings.androidBuildSystem = AndroidBuildSystem.Gradle; BuildPipeline.BuildPlayer(BuildingScenes, path, target, options); } [MenuItem("FashionBeat/Jenkins/BuildAPK")] public static void BuildAPK() { bool generateLua = GetArg("m_GenerateLua", "false") == "true"; if (generateLua) { Generator.ClearAll(); Generator.GenAll(); } string path = GetArg("m_ExportPath", ""); if (string.IsNullOrEmpty(path)) { path = "../../1.apk"; } Debug.Log("m_ExportPath=" + path); if (File.Exists(path)) File.Delete(path); string dirPath = Path.GetDirectoryName(path); if (!Directory.Exists(dirPath)) Directory.CreateDirectory(dirPath); BuildTarget target = BuildTarget.Android; BuildOptions options = BuildOptions.None; EditorUserBuildSettings.exportAsGoogleAndroidProject = false; //EditorUserBuildSettings.androidBuildSystem = AndroidBuildSystem.Gradle; BuildPipeline.BuildPlayer(BuildingScenes, path, target, options); } [MenuItem("FashionBeat/Jenkins/ExportLoc")] public static void ExportLoc() { bool getChinese = GetArg("m_GetChinese", "true") == "true"; string folder = GetArg("m_ExportPath", "C:\\"); Language lan = (Language)Enum.Parse(typeof(Language), GetArg("m_Language", "English")); if (getChinese) { LocalizationTools.Jenkins_GetChinese(); } LocalizationTools.Jenkins_ExportUnloc(lan, folder); LocalizationTools.Jenkins_ExportAllLocText(folder); } public static void ImportLoc() { string path = GetArg("m_LocalizedExcel", ""); Language lan = (Language)Enum.Parse(typeof(Language), GetArg("m_Language", "English")); if (!string.IsNullOrEmpty(path)) { LocalizationTools.Localize(lan, path); } } }
9,配置在jenkins中的shell代码,如:
#!${GitBashPath} sh ${JenkinsCode}/BuildApkWithSDK.sh "${Unity2020_341}" "${ProjectTwAndroid}" "Android" ${m_ProductCode}
转载请注明出处:https://www.cnblogs.com/jietian331/p/16921891.html
标签:shell,string,path,BuildTarget,Jenkins,分享,true,GetArg From: https://www.cnblogs.com/jietian331/p/16921891.html