学习目标:在已有SVN前提上,对SVN的项目进行自动打包
参考资料:
https://blog.csdn.net/nankeyixiao/article/details/79948608
关于上面的.\LocalSVNRoot/20200210Main是相对于任务文件目录的相对路径,如下所示。
这个文件夹会在构建的时候自动从SVN的地址检出,也就是SVN的一个副本,这个Jenkins任务构建的工程就是这个本地项目!而不是SVN上的项目。
-quit -batchmode -projectPath E:\jenkins\workspace\第二个Jenkins任务SVN\LocalSVNRoot\20200210Main -executeMethod UnityProjectBuilder.CommandLineBuild -logFile JenkinsBuildUnity.log Platform-$Platform BuildPath-$BuildPath
上面的构建字符串肯定是要改的,如何改?关于上面的字符串在我另一篇文章有介绍就不在此阐述了~
上面链接文章中的C#脚本有更新,如下所示,将其放入Editor文件夹下即可。
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class UnityProjectBuilder
{
static string[] GetBuildScenes()
{
List<string> names = new List<string>();
foreach (EditorBuildSettingsScene e in EditorBuildSettings.scenes)
{
if (e == null)
continue;
if (e.enabled)
names.Add(e.path);
}
return names.ToArray();
}
/// <summary>
/// 此方法是从jienkins上接受 数据的 方法
/// </summary>
static void CommandLineBuild()
{
try
{
Debug.Log("Command line build\n------------------\n------------------");
string[] scenes = GetBuildScenes();
//string path = @"E:\Unity游戏包\Android\消消乐游戏";//这里的路径是打包的路径, 定义
string path = GetJenkinsParameter("BuildPath");
Debug.Log("构建路径:" + path);
for (int i = 0; i < scenes.Length; ++i)
{
Debug.Log(string.Format("Scene[{0}]: \"{1}\"", i, scenes[i]));
}
// ProjectPackageEditor.BuildByJenkins(GetJenkinsParameter("Platform"), GetJenkinsParameter("AppID"), GetJenkinsParameter("Version"), GetJenkinsParameter("IPAddress"));
Debug.Log("Starting Build!");
Debug.Log(GetJenkinsParameter("Platform"));
string platform = GetJenkinsParameter("Platform");
if (platform == "Android")
{
Debug.Log("打包Android");
BuildPipeline.BuildPlayer(scenes, path + ".apk", BuildTarget.Android, BuildOptions.None);
}
else if (platform == "IOS")
{
//BuildPipeline.BuildPlayer(scenes, path, BuildTarget.iOS, BuildOptions.AcceptExternalModificationsToPlayer);
}
else if(platform == "Window")
{
Debug.Log("打包Window");
BuildPipeline.BuildPlayer(scenes, path + ".exe", BuildTarget.StandaloneWindows64, BuildOptions.None);
}
}
catch (Exception err)
{
Console.WriteLine("方法F中捕捉到:" + err.Message);
throw;//重新抛出当前正在由catch块处理的异常err
}
finally
{
Debug.Log("----------> I am copying! <--------------");
}
}
/// <summary>
///解释jekins 传输的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
static string GetJenkinsParameter(string name)
{
foreach (string arg in Environment.GetCommandLineArgs())
{
Debug.Log("arg:" + arg);
if (arg.StartsWith(name))
{
return arg.Split("-"[0])[1];
}
}
return null;
}
}
构建成功后