目的:安排配置管理人员对产品进行版本包的管理工作,使开发人员无需频繁进行打包工作,也有利于进行产品的版本控制。
方法:使用Jenkins,该工具能完成不限于unity3d的各种编译工具的打包工作。
详细步骤:(windows环境下)
1、进入主页,可以看到常规的用户界面,一共分为三大块;
2、新建一个项目,选中该项目,可以进入项目配置界面;
3、进行配置界面的脚本编写工作,可以看到项目的脚本编辑界面;
重点是Build模块,build environment需要设置项目名称等,其他模块采用默认就行。
4、重头戏Build模块代码编写;
Execute windows batch command分三部分,也可以合并为一部分
获取用户名称的代码块
exit 0
if not exist %customer% (
mkdir %customer%
)
cd %customer%
if not exist %version% (
mkdir "%version%"
) else (
rd /s/q %version%
mkdir "%version%"
)
cd %version%
exit 0
通过svn进行版本代码下载的代码块
exit 0
::获取log版本号下载最新或某个版本代码
cd %customer%%version%
if "%log%" == "true" (
svn checkout -r %revision% %repository%
) else (
svn checkout %repository%
)
set svnURL= %repository%
svn info %svnURL% | findstr "Rev:" > Version.txt
for /f "tokens=4 delims= " %%i in (Version.txt) do set revision=%%i
echo %revision%
exit 0
执行unity3d打包的代码块
::exit 0
::判断Unity是否运行中
TASKLIST /V /S localhost /U %username%>tmp_process_list.txt
TYPE tmp_process_list.txt |FIND "Unity.exe"
IF ERRORLEVEL 0 (GOTO UNITY_IS_RUNNING)
ELSE (GOTO START_UNITY)
:UNITY_IS_RUNNING
::杀掉Unity
TASKKILL /F /IM Unity.exe
::停1秒
PING 127.0.0.1 -n 1 >NUL
set UNITY_Version=%version%
set SVNRevision=%revision%
set PROJECT_PATH=E:jenkinsworkspaceBIM%customer% ::这里是uniyt3d项目工程的存放位置
set UNITY_OUT_PATH=E:JenkinsProducts%customer% ::这里是产品输出的路径存放位置
set UNITY_PATH=F:GameDevelopU3D_Hub2019.1.8f1Editor ::这里是uniyt3d的安装位置
set UNITY_LOG_PATH=%cd%unity_log.txt
echo lunch unity.exe ,please wait a moment...
GOTO START_UNITY
:START_UNITY
f:
::进入了F盘,因为unity3d安装在F盘
cd %UNITY_PATH%
.Unity.exe -projectPath %PROJECT_PATH% -logFile %UNITY_LOG_PATH% -quit -batchmode -executeMethod BatCall.UnityBuild --version=%UNITY_Version% --name=%SVNRevision% --outpath=%UNITY_OUT_PATH%
echo "Build exe done"
::执行打包工作
pause
5、在unity3d项目的Editor文件夹下,需要加入下面的脚本
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
/// <summary>
/// 供批处理打包pc端项目调用
/// </summary>
public class BatCall : MonoBehaviour {
[MenuItem("Tools/Build")]
public static void UnityBuild()
{
Debug.logger.logEnabled = true;
List<string> args = new List<string>();
foreach (string item in System.Environment.GetCommandLineArgs())
{
if (item.StartsWith("--")) {
string arg = item.Split('=')[1];
args.Add(arg);
Debug.Log("arg: "+arg);
}
}
//按照顺序三个参数依次是version, SVNRevision, UNITY_OUT_PATH
string outputPath = args[2] + @"" + args[0] + "_" + args[1] + ".exe";
//string outputPath = args[1] + @"" + args[0] + "_hhh.exe";
Debug.Log("outputPath :"+outputPath);
//string NowPath = "D:BatBuildBuild_CamCam.exe";
BuildPipeline.BuildPlayer(GetBuildScenes(), outputPath, BuildTarget.StandaloneWindows64, BuildOptions.None);
}
static string[] GetBuildScenes()
{
List<string> pathList = new List<string>();
foreach (EditorBuildSettingsScene scene in EditorBuildSettings.scenes)
{
if (scene.enabled)
{
pathList.Add(scene.path);
Debug.Log(scene.path);
}
}
return pathList.ToArray();
}
}
6、回到项目的配置功能界面,点击Release等待项目自动编译打包;
提示Success则大功告成。