1. 程式人生 > >在mac上構建Jenkins+unity3d+xcode釋出流程

在mac上構建Jenkins+unity3d+xcode釋出流程

2.啟動jenkis

#sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist

#java -jar /Applications/jenkins.war -httpPort=8080

jenkin會在/Users/[User Name]/.jenkins建立工作目錄

3.在系統管理->管理外掛裡面安裝xCode Plugin,Unity3d Plugin,Publish Over FTP安裝完重啟。也可到官網去下載hdi外掛直接安裝。

4.新建一個“構建自由風格的軟體專案”,並取名為test。原始碼管理選擇subversion,填入地址和使用者名稱密碼。(在這裡博主卡了很久,如果發現使用者名稱和密碼一直不能通過驗證,可以再終端下面使用 "svn co [專案地址] --username [使用者名稱] --password [密碼]"看是否能checkout,如果可以,說明你填寫的使用者名稱和密碼沒有問題,反之有問題).

基本配置如下,這時候可以儲存一下,並點選左邊的構建,讓jenkins撿出一下專案,撿出完畢發現test任務下面的工作空間下的工作區內會有檔案。


5.撿出完畢,回到jenkins的根頁進入系統管理->系統設定找到unity3d,點選unity3d安裝可配置unity3d的相關引數

別名:unity4.6.6

安裝目錄:/Applications/Unity/Unity.app

然後點選儲存.

6.再次回到jenkins的根頁點選test任務,進入該任務後繼續點選左邊的配置選項,繼續進行剛才未完成的配置

在頁面上找到增加構建步驟,選擇Invoke Unity3d Editor,這時候

Unity3d installation name 已預設選中剛才我們設定的別名unity4.6.6

Editor command line arguments   -projectPath ${WORKSPACE}/3d_client -executeMethod PerformBuild.CommandLineBuild -batchmode -quit

7.在unity3d當中建立PerformBuild.cs檔案並放入Editor檔案下面,寫入如下程式碼.該程式碼會在Tools選單下面生成PerformBuild子選單,可測試是否能匯出。

using System.IO;
using System.Collections;
using UnityEngine;
using System.Collections.Generic;

class PerformBuild
{
	static string[] GetBuildScenes()
	{
		List<string> names = new List<string>();
		
		foreach(UnityEditor.EditorBuildSettingsScene e in UnityEditor.EditorBuildSettings.scenes)
		{
			if(e==null)
				continue;
			
			if(e.enabled)
				names.Add(e.path);
		}
		return names.ToArray();
	}
	
	static string GetBuildPath()
	{
		string dirPath = Application.dataPath +"/../../build";
		if(!System.IO.Directory.Exists(dirPath)){
			System.IO.Directory.CreateDirectory(dirPath);
		}
		return dirPath;
	}
	
	[UnityEditor.MenuItem("Tools/PerformBuild/Test Command Line Build iPhone Step")]
	static void CommandLineBuild ()
	{
		Debug.Log("Command line build\n------------------\n------------------");
		
		string[] scenes = GetBuildScenes();
		string path = GetBuildPath();
		if(scenes == null || scenes.Length==0 || path == null)
			return;
		
		Debug.Log(string.Format("Path: \"{0}\"", path));
		for(int i=0; i<scenes.Length; ++i)
		{
			Debug.Log(string.Format("Scene[{0}]: \"{1}\"", i, scenes[i]));
		}
		
		Debug.Log("Starting Build!");
		UnityEditor.BuildPipeline.BuildPlayer(scenes, path, UnityEditor.BuildTarget.iPhone, UnityEditor.BuildOptions.None);
	}
	
	static string GetBuildPathAndroid()
	{
		string dirPath = Application.dataPath +"/../../../build/android";
		if(!System.IO.Directory.Exists(dirPath)){
			System.IO.Directory.CreateDirectory(dirPath);
		}
		return dirPath;
	}
	
	[UnityEditor.MenuItem("Tools/PerformBuild/Test Command Line Build Step Android")]
	static void CommandLineBuildAndroid ()
	{
		Debug.Log("Command line build android version\n------------------\n------------------");
		
		string[] scenes = GetBuildScenes();
		string path = GetBuildPathAndroid();
		if(scenes == null || scenes.Length==0 || path == null)
			return;
		
		Debug.Log(string.Format("Path: \"{0}\"", path));
		for(int i=0; i<scenes.Length; ++i)
		{
			Debug.Log(string.Format("Scene[{0}]: \"{1}\"", i, scenes[i]));
		}
		
		Debug.Log("Starting Android Build!");
		UnityEditor.BuildPipeline.BuildPlayer(scenes, path, UnityEditor.BuildTarget.Android, UnityEditor.BuildOptions.None);
	}
}
8.再次增加構建步驟,選擇xcode,並如下設定,並儲存。

9.給專案安裝證書,下載相關證書並雙擊安裝即可,保證xcodeproj能成功編譯到device即可

如果是遠端電腦可用Finder->連線伺服器 vnc://172.16.0.xx 連線遠端電腦並安裝證書.

10.上傳到ftp伺服器,系統管理->系統設定配置ftp伺服器資訊


11.配置test任務,增加構建後步驟選擇Send files Over FTP,並如下配置。


12.執行構建,成功構建後你的ftp上就會有ipa包。

13.後續可增加發送郵件,在郵件內使用item-service進行安裝(暫未實現).