本文多是網上最全的一篇全端jenkins部署解決方案介紹的文章,一直以來,領導都想解決代碼提交和打包問題,尤爲是小公司,打包流程混亂,形成線上版本和代碼庫git或svn中代碼不一致問題。加入jenkins陣營,解決衆多發包難題,顯得刻不容緩。java
剛開始,我一直在docker下安裝jenkins,按時長租用阿里的主機,用阿里容器服務作實驗,反覆建立docker容器,創建多個jenkins節點。結果發現,在容器中配置各類變量比較複雜,各類開發環境不易快速部署,固然啦,是剛開始的對jenkins研究過少形成的。後來我採用了windows主機,配java、maven、Android環境,踩了一路坑,終於搞定了。可是我知道ios開發和編譯必須使用mac系統,原本想增長一個jenkins節點來實現ios的編譯。當配置好以後,我忽然改變了主意,與其兩臺電腦開着,不如索性把整個jenkins部署到mac系統下(畢竟咱們公司暫時沒有c#工程)。因而,全部的操做,全部的環境我又折騰了一遍。下面我逐一講解最終mac下實現全端jenkins持續集成,固然不包含c#,一路踩坑下來,我以爲這都不是事,流程都差很少。android
我我的比較喜歡新事物,因此建議使用較高版本,我使用的2.61,目前最新版是2.75。
mac下使用brew安裝,終端執行ios
brew install jenkins複製代碼
等安裝完成後,終端運行jenkins便可啓動。git
jenkins複製代碼
這個比較簡單,直接從appstore下載最新版便可。
安裝後,將公司項目拉入xcode,先保證項目在本機編譯,這裏我登陸了app開發者賬號,以便下載各類證書及發佈。github
這個到這裏下載www.android-studio.org/docker
由於咱們公司用的是git,若是貴公司使用svn,則同理,只需保git或者svn命令能夠敲出來便可。
我這裏的版本比較老,儘可能使用新的,我懶得換了。c#
mac:~ shaolei$ git version
git version 2.11.0複製代碼
這是一個很是好用的git可視化工具,改天會具體介紹它的強大功能。
這款軟件不是必須的,只是爲了方便項目拉取,因此,你能夠跳過此步驟。windows
這裏纔是相當重要的一項,本文的核心xcode
Starts an Android emulator with given properties before a build, then shuts it down after.複製代碼
This plugin allows builds to be automatically terminated after the specified amount of time has elapsed.複製代碼
This plugin is a replacement for Jenkins's email publisher 複製代碼
This plugin allows Jenkins to invoke Gradle build scripts directly.複製代碼
This plugin integrates management of keychain and provisioning files for iOS and OSX projects.複製代碼
This plug-in provides, for better and for worse, a deep integration of Jenkins and Maven: Automatic triggers between projects depending on SNAPSHOTs, automated configuration of various Jenkins publishers (Junit, ...). 複製代碼
A suite of plugins that lets you orchestrate automation, simple or complex. See Pipeline as Code with Jenkins for more details. 複製代碼
Allows Pipeline Grrovy libraries to be loaded on the fly from GitHub.複製代碼
Allows to launch agents over SSH, using a Java implementation of the SSH protocol.複製代碼
Subversion Plug-inandroid-studio
Timestamper
Adds timestamps to the Console Output複製代碼
This plugin deletes the project workspace after a build is finished.複製代碼
This plugin provides builders to build xcode projects, invoke agvtool and package .ipa files複製代碼
其中Android Emulator Plugin、Gradle Plugin是安卓必須插件;其中Keychains and Provisioning Profiles Management、Pipeline、Xcode integration是ios編譯必須插件;其中Maven Integration plugin、SSH Slaves plugin是maven項目必須插件,其餘的Email Extension Plugin這個是爲了編譯失敗的時候通知具體提交代碼開發人員郵件
建立安卓job
和安卓相同的源代碼管理及觸發器不作介紹,請參照安卓,下文同理。
cd ${WORKSPACE}
mvn clean
cd ${WORKSPACE}/******/src/main/resources/
echo ${BUILD_NUMBER} >ver.xml複製代碼
固然了,這裏用到了幾個關鍵詞變量,是jenkins特有的,更多變量參照下文:
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
…………………………………………等等複製代碼
這裏我就用了zip打包,部署時使用zip解壓到指定目錄便可。
cd ${WORKSPACE}
echo ${BUILD_NUMBER} >ver.txt
zip -r h5.zip ./ -x .git\* -x README.md -x .project -x .gitignore
cp ${WORKSPACE}/h5.zip /Volumes/***/H5/h5-${BUILD_NUMBER}.zip複製代碼
本文全面講解了jenkins各項目持續繼承方案,由於涉及環境過多,坑仍是比較多的,但願自行填坑。