Programmer:)
[Unity] CMD로 Build 하는 방법 본문
반응형
CMD에서 Unity Script 함수를 실행하여 빌드진행
BuildTarget : Windows, OSX ...
Architecture : 32bit or 64bit
public static void BuildStart(string buildTarget, string at)
{
BuildPath = string.Format(@"Build/{0}/{1}/{2}/Client", buildTarget, at, Application.version);
DirectoryInfo DirInfo = new DirectoryInfo(BuildPath);
if (DirInfo.Exists == false)
DirInfo.Create();
string[] Scenes;
List<string> EditorScenes = new List<string>();
foreach(EditorBuildSettingsScene scene in EditorBuildSettings.scenes)
{
if (!scene.enabled) continue;
EditorScenes.Add(scene.path);
}
Scenes = EditorScenes.ToArray();
BuildReport report = null;
if (buildTarget.Equals("StandaloneWindows"))
{
EditorUserBuildSettings.selectedStandaloneTarget = BuildTarget.StandaloneWindows;
if (at.Equals("64"))
report = BuildPipeline.BuildPlayer(Scenes, string.Format(@"{0}/{1}.exe", BuildPath, Application.productName), BuildTarget.StandaloneWindows64, BuildOptions.None);
else
report = BuildPipeline.BuildPlayer(Scenes, string.Format(@"{0}/{1}.exe", BuildPath, Application.productName), BuildTarget.StandaloneWindows, BuildOptions.None);
}
else if (buildTarget.Equals("StandaloneOSX"))
{
EditorUserBuildSettings.selectedStandaloneTarget = BuildTarget.StandaloneOSX;
report = BuildPipeline.BuildPlayer(Scenes, string.Format(@"{0}/{1}.app", BuildPath, Application.productName), BuildTarget.StandaloneOSX, BuildOptions.None);
}
BuildSummary summary = report.summary;
switch (report.summary.result)
{
case BuildResult.Succeeded:
Debug.Log("Succeeded");
break;
case BuildResult.Failed:
Debug.Log("Failed");
break;
}
}
BuildPipeline.BuildPlayer() 이 함수가 실질적 빌드 진행 부분.
cmd로 인자 값 받아서 buildtarget, architectrue 설정해주고 싶었기 때문에 인자값 받을 수 있는 함수 추가
cmd에서 BuildStartInJenkins 호출하면 완료.
public static void BuildStartInJenkins()
{
string buildTarget = GetArg("-buildTarget");
string at = GetArg("-at");
BuildStart(buildTarget, at);
}
private static string GetArg(string name)
{
var args = System.Environment.GetCommandLineArgs();
for (int i = 0; i < args.Length; i++)
{
if (args[i] == name && args.Length > i + 1)
{
return args[i + 1];
}
}
return null;
}
cmd에서 아래 형식으로 build 진행하면 끝
"C:\Program Files\Unity\Hub\Editor\2019.4.3f1\Editor\unity.exe" -quit -batchmode -projectPath "D:\Dev\Main\TEST" -executeMethod ProjectBuild.BuildStartInJenkins -buildTarget "StandaloneWindows" -at "64"
-logFile "D:\Dev\Main\TEST\Build\logfile.log"
반응형
'DEV > Jenkins' 카테고리의 다른 글
[Jenkins] Home Directory 변경하기 (0) | 2024.07.10 |
---|---|
[Jenkins] mac homebrew 이용 remove (0) | 2024.02.19 |
[Jenkins]Disable Workspace Cleanup (0) | 2022.08.19 |
[Jenkins] Google Play Store Upload - PipeLine (2024.07.16 업데이트) (0) | 2022.05.24 |
[Jenkins] Fastlane - PipeLine (UTF-8 error ) (0) | 2022.05.24 |
Comments