? ? ? 首先止状,Jenkins官網(wǎng)地址
? ? ? 正常的下載安裝后jenkins會(huì)彈出一個(gè)網(wǎng)頁,可以進(jìn)行注冊(cè)賬號(hào)與初始化攒霹,開始要下載一些插件怯疤,可以讓jenkins自動(dòng)下載。經(jīng)過簡單的初始化設(shè)置之后我們可以進(jìn)入一個(gè)這樣的界面:
1.授權(quán)其他用戶登錄與權(quán)限控制
在這里可以進(jìn)入用戶全局隱私設(shè)置
? ? ? 在這里可以決定是否允許用戶注冊(cè)催束,下面是權(quán)限的授權(quán)策略集峦,途中目前選擇的是登錄的用戶可以做所有事,當(dāng)然也可以使用下面的安全矩陣
模式抠刺,該模式通過一個(gè)表來配置哪些用戶可以做哪些事情塔淤。
2.添加節(jié)點(diǎn)(執(zhí)行構(gòu)建的節(jié)點(diǎn),也就是電腦)
? ? ? 當(dāng)有很多功能需要進(jìn)行構(gòu)建的時(shí)候速妖,我們有時(shí)希望讓不同的電腦來執(zhí)行不同的構(gòu)建函數(shù)高蜂,這個(gè)時(shí)候我們就要添加更多的節(jié)點(diǎn)進(jìn)來。
? ? ? 還是在剛才的Manage Jenkins選項(xiàng)中罕容,找到Manage Nodes選項(xiàng)
? ? ? 在左側(cè)選項(xiàng)卡中選擇新建節(jié)點(diǎn)后备恤,給節(jié)點(diǎn)起一個(gè)名字集侯,然后選擇Permanent Agent夭委,也可以選擇使用現(xiàn)有的配置(如果之前已經(jīng)創(chuàng)建過節(jié)點(diǎn))生成一個(gè)全新的節(jié)點(diǎn)。
? ? ? 寫好名稱赢织,遠(yuǎn)程根目錄和標(biāo)簽生闲。這里的遠(yuǎn)程目錄用于存儲(chǔ)Jenkins客戶端運(yùn)行文件瘫镇。其他設(shè)置默認(rèn)值就可以了汞斧。這個(gè)時(shí)候生成的節(jié)點(diǎn)是未連接狀態(tài)瞪浸,可以用其他的電腦訪問你的Jenkins,經(jīng)過一系列設(shè)置就可以連接上了沉噩。(這一部分因?yàn)橹挥幸慌_(tái)電腦捺宗,而且暫時(shí)沒有使用其他節(jié)點(diǎn)的需求,這里只是做一個(gè)demo讓本地能跑通屁擅,所以這里其實(shí)沒有實(shí)際操作過偿凭,暫時(shí)粘點(diǎn)百度來的流程产弹,如果后面有使用再補(bǔ)上)
3.創(chuàng)造一個(gè)構(gòu)建任務(wù)
? ? ? 首先派歌,在工作臺(tái)中選擇新建一個(gè)任務(wù)
? ? ? 然后我們可以自己創(chuàng)建一個(gè)自由風(fēng)格的工程,在這個(gè)界面痰哨,我們同樣可以選擇一個(gè)已經(jīng)創(chuàng)建好的構(gòu)建任務(wù)進(jìn)行復(fù)制胶果,操作和上面復(fù)制節(jié)點(diǎn)類似(只要輸入構(gòu)建任務(wù)名就可以)。
1.我們可以自己定義一些構(gòu)建任務(wù)參數(shù)斤斧,上面指的是構(gòu)建的結(jié)果是否刪除早抠,里面可以自定義最多保存這個(gè)任務(wù)的多少個(gè)構(gòu)建結(jié)果,以及構(gòu)建結(jié)果保存的天數(shù)撬讽。
2.下面的選項(xiàng)可以配置這個(gè)構(gòu)建任務(wù)是否需要參數(shù)蕊连,如果勾選后可以給shell文件傳遞一些參數(shù)過去,也就可以得到不同的構(gòu)建結(jié)果游昼,我們?cè)诤竺娣帕艘粡堖x擇的構(gòu)建參數(shù)界面甘苍。(是否參數(shù)化要看具體的構(gòu)建任務(wù)需求,本項(xiàng)為可選項(xiàng))
然后就是關(guān)鍵的構(gòu)建部分了:
1.添加一個(gè)構(gòu)建步驟:
? ? ? 這里要注意一下烘豌,很多教程寫的是Execute shell载庭,但是這個(gè)是針對(duì)linux平臺(tái)的(或者mac也可以?)廊佩,我用的是Windows平臺(tái)囚聚,使用Execute shell構(gòu)建時(shí)會(huì)報(bào)錯(cuò)找不到文件The system cannot find the file specified
。
? ? ? Windows平臺(tái)請(qǐng)使用第一個(gè)Execute Windows batch command标锄。
2.添加一個(gè)測試腳本顽铸,測試腳本代碼很簡單,只有一行echo YES!
3.測試料皇!啟動(dòng)谓松!構(gòu)建簸淀!
? ? ? 回到工作臺(tái),點(diǎn)擊右邊的按鈕就可以對(duì)該任務(wù)進(jìn)行構(gòu)建了毒返,構(gòu)建的結(jié)果也會(huì)寫在邊上租幕,可以進(jìn)入對(duì)應(yīng)的構(gòu)建版本號(hào)查看log日志。
4.使用Jenkins與Unity進(jìn)行交互
? ? ?首先我們需要寫一個(gè)簡單的bat腳本拧簸,使用這個(gè)bat腳本可以調(diào)用unity中的某個(gè)函數(shù)劲绪。Unity有提供對(duì)應(yīng)的API給我們,可以說很貼心了盆赤。Unity API
? ? ?下面是我自己做demo使用的bat代碼贾富,很簡單只有一行。其中各個(gè)代碼含義都可以在API中找到牺六,
-quit 表示執(zhí)行完程序自動(dòng)退出
-batchmode 表示使用批處理模式颤枪,不會(huì)進(jìn)行彈窗,如果過程中出錯(cuò)會(huì)自動(dòng)退出
-projectPath 表示你的工程地址
-logFile 表示unity輸出的log地址
-executeMethod 表示你要執(zhí)行的類名.函數(shù)名(可以傳參淑际,在后面加一個(gè)空格后傳入畏纲,可以在Jenkins中添加參數(shù)化功能,然后傳到這里春缕。這里要注意一下盗胀,這個(gè)腳本要放在Editor文件夾下
)
? ? ?這里的log沒有指定位置,會(huì)直接生成在Jenkins的工作空間下锄贼,這樣在Jenkins上就可以直接查看輸出的log文件了票灰。
D:/Unity/Editor/Unity.exe -quit -batchmode -projectPath E:/NewUnityProject -logFile build.log -executeMethod MyEditorScript.MyMethod
? ? ?接下來是測試用C#代碼,也很簡單宅荤,就一句log
using UnityEngine;
class MyEditorScript
{
static void MyMethod()
{
Debug.Log("I am Unity!!!!!!!!");
}
}
然后就是和上面相同的流程了屑迂,使用Jenkins構(gòu)建,然后可以查看一下生成的log文件~
I am Unity!!!!!!! 然后剩下的就是發(fā)揮大家的想象力冯键,使用Jenkins做很多平時(shí)要我們自己浪費(fèi)時(shí)間做的事啦~比如打包呀惹盼,檢查資源呀什么的。
番外.一些動(dòng)手過程中遇到的問題
1.Jenkins位置:
? ? ? 在瀏覽器里面打開http://localhost:8080/ 局域網(wǎng)內(nèi)別人可以打開http://”你的ip”:8080/
2.如何重啟或重新加載Jenkins?
重啟:http://localhost:8080/restart
重新加載配置:http://localhost:8080/reload
3.如何修改Jenkins端口號(hào):
打開安裝目錄下的jenkins.xml文件琼了,修改 <arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=8081</arguments>
4.關(guān)于Jenkins的環(huán)境變量:
環(huán)境變量可以在Jenkins構(gòu)建函數(shù)編寫的地方查看逻锐,這里只是做一個(gè)復(fù)讀機(jī),整理一下方便以后使用的時(shí)候查看
變量名 | 說明 |
---|---|
BRANCH_NAME | For a multibranch project, this will be set to the name of the branch being built, for example in case you wish to deploy to production from master but not from feature branches; if corresponding to some kind of change request, the name is generally arbitrary (refer to CHANGE_ID and CHANGE_TARGET). |
CHANGE_ID | For a multibranch project corresponding to some kind of change request, this will be set to the change ID, such as a pull request number, if supported; else unset. |
CHANGE_URL | For a multibranch project corresponding to some kind of change request, this will be set to the change URL, if supported; else unset. |
CHANGE_TITLE | For a multibranch project corresponding to some kind of change request, this will be set to the title of the change, if supported; else unset. |
CHANGE_AUTHOR | For a multibranch project corresponding to some kind of change request, this will be set to the username of the author of the proposed change, if supported; else unset. |
CHANGE_AUTHOR_DISPLAY_NAME | For a multibranch project corresponding to some kind of change request, this will be set to the human name of the author, if supported; else unset. |
CHANGE_AUTHOR_EMAIL | For a multibranch project corresponding to some kind of change request, this will be set to the email address of the author, if supported; else unset. |
CHANGE_TARGET | For a multibranch project corresponding to some kind of change request, this will be set to the target or base branch to which the change could be merged, if supported; else unset. |
BUILD_NUMBER | The current build number, such as "153" |
BUILD_ID | The current build ID, identical to BUILD_NUMBER for builds created in 1.597+, but a YYYY-MM-DD_hh-mm-ss timestamp for older builds |
BUILD_DISPLAY_NAME | The display name of the current build, which is something like "#153" by default. |
JOB_NAME | Name of the project of this build, such as "foo" or "foo/bar". |
JOB_BASE_NAME | Short Name of the project of this build stripping off folder paths, such as "foo" for "bar/foo". |
BUILD_TAG | String of "jenkins- |
EXECUTOR_NUMBER | The unique number that identifies the current executor (among executors of the same machine) that’s carrying out this build. This is the number you see in the "build executor status", except that the number starts from 0, not 1. |
NODE_NAME | Name of the agent if the build is on an agent, or "master" if run on master |
NODE_LABELS | Whitespace-separated list of labels that the node is assigned. |
WORKSPACE | The absolute path of the directory assigned to the build as a workspace. |
JENKINS_HOME | The absolute path of the directory assigned on the master node for Jenkins to store data. |
JENKINS_URL | Full URL of Jenkins, like http://server:port/jenkins/ (note: only available if Jenkins URL set in system configuration) |
BUILD_URL | Full URL of this build, like http://server:port/jenkins/job/foo/15/ (Jenkins URL must be set) |
JOB_URL | Full URL of this job, like http://server:port/jenkins/job/foo/ (Jenkins URL must be set) |