赞
踩
这里推荐使用命令行安装,这样基本不会弹出权限问题,如果直接使用dmg包进行安装,在自动化的过程中会弹出很多权限弹窗。
Mac Jenkins下载地址:https://www.jenkins.io/download/lts/macos/
进入以后出现以下界面
打开终端,复制命令 安装Jenkisn
brew install jenkins-lts
等待结束之后就安装成功了。
然后输入命令:
brew services start jenkins-lts
启动Jenkisn
启动完成后打开浏览器 输入:http://localhost:8080 进入Jenkins后台。
在进入之前需要输入管理员密码以及下载一堆插件,需要等待些时间。
等插件安装完成之后我们的Jenkins就算跑起来了。
然后点击 系统管理-插件管理 进入插件下载界面
接着在可选插件中 搜索Unity 安装一下Unity3d Plugins ,我这里已经安装过了。
Unity3d Plugins 安装完成之后 点击 系统管理-全局工具配置
进入之后配置一下我们打包的Unity引擎路径以及版本号
配置完成之后,我们就可以去创建打包工程了。
1.新建任务
工程创建完成之后,根据项目需求配置一下Unity打包时需要的参数,一般来说常用的是布尔,选项参数(枚举),和String 字符
工程路径一定要配上
其余的参数跟据自己的需求随意配置。
配置完成之后,我们就可以把参数传给Unity了。
这里笔者把参数写成了一个txt文件,放到了Unity Asset同级的目录下,以便Unity在打包时,能够得到参数。
#写入参数
echo "Version:${Version}:VersionCode:${VersionCode}:Name:${Name}:MulRedering:${MulRedering}:Release:${Release}:OpenLog:${OpenLog}:isShowVersion:${isShowVersion}:isConfusion:${isConfusion}:teamCode:${teamCode}"> ${WorkPath}/jenkinsParam.txt
${version} 表示取version的值
以:进行拼接,key为Version,value为Version的值。
拼接完成后写入 workPath工程目录下,名字为JenkinsParam.txt
配置如下:
#调用Unity方法进行打包
/Applications/Unity/Unity.app/Contents/MacOS/Unity -projectPath ${WorkPath} -executeMethod BuildApp.BuildiOS -quit -batchmode
cd ${WorkPath}
在使用Jenkins打包时要确保该工程已经关闭,否则打包会出错。
上面方法表面调用 Unity工程下的BuildApp.BuildiOS方法
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;
using System.IO;
using LitJson;
/// <summary>
/// 发布APP
/// </summary>
public class BuildApp
{
public static string m_AndroidPath = Application.dataPath + "/../BuildTarget/Android/";
public static string m_IOSPath = Application.dataPath + "/../BuildTarget/IOS/";
public static string m_JenkinsParamPath = Application.dataPath + "/../jenkinsParam.txt";
[MenuItem("Build/IOS")]
public static void BuildiOS()
{
PlayerSettings.iOS.buildNumber = "1.0";
#if UNITY_WINDOW
BuildSeting buildSeting = GetAndroidBuildSetring();
#else
BuildSeting_iOS buildSeting = MacGetiOSSeting();
#endif
string suffx = iOSSeting(buildSeting);
AssetDatabase.Refresh();
//绝对储存路径
//string savePath = m_IOSPath + buildSeting.Name + "_iOS" + suffx + string.Format("_{0:yyyy_MM_dd_HH_mm}", DateTime.Now);
string savePath = m_IOSPath;
if (File.Exists(savePath))
{
JenkinsTools.DeleteDir(savePath);
}
Debug.Log(savePath);
BuildPipeline.BuildPlayer(FindEnableEditorrScenes(), savePath, EditorUserBuildSettings.activeBuildTarget, BuildOptions.None);
}
private static string[] FindEnableEditorrScenes()
{
List<string> editorScenes = new List<string>();
foreach (EditorBuildSettingsScene scene in EditorBuildSettings.scenes)
{
if (!scene.enabled) continue;
editorScenes.Add(scene.path);
}
return editorScenes.ToArray();
}
[MenuItem("Build/打开日志")]
public static void LoadReprot()
{
GameObject obj = GameObject.Find("Reporter");
if (obj == null)
{
GameObject reportObj = GameObject.Instantiate(AssetDatabase.LoadAssetAtPath<GameObject>("Assets/ThirdParty/Unity-Logs-Viewer/Reporter.prefab"));
reportObj.name = "Reporter";
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
}
[MenuItem("Build/关闭日志")]
public static void DestoryReprot()
{
GameObject obj = GameObject.Find("Reporter");
if (obj != null)
{
GameObject.DestroyImmediate(obj);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
}
[MenuItem("Build/读取IOS参数")]
public static BuildSeting_iOS MacGetiOSSeting()
{
BuildSeting_iOS seting = new BuildSeting_iOS();
string jenkinsParam = File.ReadAllText(m_JenkinsParamPath);
Debug.Log(jenkinsParam);
string[] Params = jenkinsParam.Split(':');
for (int i = 0; i < Params.Length; i++)
{
Debug.Log(Params[i]);
string key = Params[i];
string value = "";
if (i < Params.Length - 1)// key vlaue Out index
{
value = Params[i + 1];// Get Value
}
if (string.Equals(key, "Version"))
{
seting.Version = value;
}
else if (string.Equals(key, "VersionCode"))
{
seting.VersionCode = value;
}
else if (string.Equals(key, "Name"))
{
seting.Name = value;
}
else if (string.Equals(key, "MulRedering"))
{
bool.TryParse(value, out seting.MulRedering);
}
else if (string.Equals(key, "Release"))
{
bool.TryParse(value, out seting.Release);
}
else if (string.Equals(key, "OpenLog"))
{
bool.TryParse(value, out seting.OpenLog);
}
else if (string.Equals(key, "isShowVersion"))
{
bool.TryParse(value, out seting.isShowVersion);
}
else if (string.Equals(key, "isConfusion"))
{
bool.TryParse(value, out seting.isConfusion);
}
else if (string.Equals(key, "teamCode"))
{
seting.teamCode = value;
}
}
Debug.Log("seting BuildCode: " + seting.VersionCode);
Debug.Log("seting Version:" + seting.Version);
Debug.Log("seting Name:" + seting.Name);
Debug.Log("seting MulRedering:" + seting.MulRedering);
Debug.Log("seting Debug:" + seting.Release);
Debug.Log("seting OpenLog:" + seting.OpenLog);
Debug.Log("seting UpdateFishAB:" + seting.isConfusion);
return seting;
}
/// 根据读取的数据 在Unity中设置对应的参数
private static string iOSSeting(BuildSeting_iOS seting)
{
string suffx = "_";
Debug.unityLogger.logEnabled = Debuger.EnableLog = seting.OpenLog;
if (seting.OpenLog)
{
LoadReprot();
}
PlayerSettings.MTRendering = seting.MulRedering == true ? true : false;
if (seting.Release == true) //测试包 处理测试配置
{
CustomTools.SwitchReleaseServer();
suffx += "Release";
}
else
{
CustomTools.SwitchTestServer();
// 其他渠道包待定
suffx += "Test";
}
if (!string.IsNullOrEmpty(seting.Version))
{
PlayerSettings.bundleVersion = seting.Version;
suffx += "_" + seting.Version;
}
if (!string.IsNullOrEmpty(seting.VersionCode))
{
PlayerSettings.iOS.buildNumber = seting.VersionCode;
suffx += "_" + seting.VersionCode;
}
if (!string.IsNullOrEmpty(seting.Name))
PlayerSettings.productName = seting.Name; //包名
if (seting.Release)
{
EditorUserBuildSettings.development = false;
suffx += "_Release";
}
else
{
EditorUserBuildSettings.development = true;
EditorUserBuildSettings.connectProfiler = true;
}
if (seting.isShowVersion)
{
string saveStrs = ConvertToJson(seting.isShowVersion);
Utils.WriteFileWithEnding(Application.dataPath + "/Resources/" + ResourcesFolder.Txts, ResourcesFile.buildInfo, saveStrs);
}
else
{
Utils.DeleteFile(Application.dataPath + "/Resources/" + ResourcesFolder.Txts + ResourcesFile.buildInfo + ".txt");
}
if (seting.teamCode.Trim() == "teamcpdexxx")//主账号
{
Debug.LogError("设置子账号包名:" + "com.baoming.xx");
#if UNITY_IOS
BL_BuildPostProcess.bundleIdentifier = "com.baoming.xx";
#endif
}
else
{
Debug.LogError("设置子账号包名:" + "com.xxxx.xx");
#if UNITY_IOS
BL_BuildPostProcess.bundleIdentifier = "com.xxxx.xx";
#endif
}
AssetDatabase.Refresh();
return suffx;
}
}
public class BuildSeting_iOS
{
//版本
public string Version = "";
//版本声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/112055
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。