作者:lp_馬建成 授權本站轉載。
導語
本文會漸進的描述我從對CI不了解,到學習並用到開發環境的過程。jenkins的安裝部署,jenkins插件安裝,jenkins JOB配置以及shell上傳到主流測試分發平台(fir.im pgyer.com)
一、jenkins安裝啟動
直接用brew安裝
brew install jenkins
安裝沒問題的童鞋請直接跳到1.3 jenkins 啟動
jenkins自身需要java環境,安裝需要brew安裝器,當然可以選擇程序包安裝。
bash:brew: command not found 這是環境沒有安homebrew
homebrew是用於安裝unix的工具包,依賴於xcode的Command line tool
1.1安裝home-brew
官網:brew.sh
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"`
From https://github.com/Homebrew/homebrew * [new branch] master -> origin/master HEAD is now at 4a9e815 caddy: update 0.7.5 bottle. ==> Installation successful! ==> Next steps Run `brew help` to get started
終端輸入上面的信息標示brew安裝成功,請安裝
brew isntall jenkins
Run brew help to get started KatherinedeMacBook-Air:~ katherine$ brew install jenkins jenkins: Java 1.6+ is required to install this formula. You can install with Homebrew Cask: brew install Caskroom/cask/java You can download from: http://www.oracle.com/technetwork/java/javase/downloads/index.html Error: An unsatisfied requirement failed this build.
按照提示我們安裝java環境
1.2 安裝java環境
這兒建議直接去java官網下載環境去安裝,brew install Cask太慢
brew install java
KatherinedeMacBook-Air:~ katherine$ brew install java Error: No available formula for java ==> Searching formulae... app-engine-java-sdk jslint4java javarepl libreadline-java ==> Searching taps... homebrew/emacs/javaimp >Caskroom/cask/javafx-scene-builder Caskroom/cask/eclipse-java Caskroom/cask/yourkit->java-profiler Caskroom/cask/java
brew install Caskroom/cask/java
waiting ...
brew 以及 brew cask討論
//據說國際流量被限制的厲害,現在凌晨1點多,下載安裝個java sdk得喝好幾杯茶,各種vpn也被限制的厲害。
1.3 jenkins 啟動
找到jenkins目錄
/usr/local/Cellar/jenkins/1.622/libexec/jenkins.war //若ls不了,ls/usr/local/Cellar/jenkins/ 看版本號路徑,cd進入
cd /usr/local/Cellar/jenkins/1.622/libexec/
啟動jenkins
java -jar ./jenkins.war
八月 10, 2015 1:17:16 上午 hudson.WebAppMain$3 run 信息: Jenkins is fully up and running 八月 10, 2015 1:17:29 上午 hudson.model.UpdateSite updateData 信息: Obtained the latest update center data file for >UpdateSource default 八月 10, 2015 1:17:35 上午 >hudson.model.DownloadService$Downloadable load 信息: Obtained the updated data file for >hudson.tasks.Maven.MavenInstaller
一直在bash命令中,算啟動成功了,輸入地址測試下
http://localhost:8080
jenkins首頁
ok 啟動成功...
二、jenkins github相關插件安裝
到jenkins頁面,jenkins->系統管理->插件管理->可選插件中安裝以下插件
GIT plugin
GitHub plugin
Post-Build Script Plug-in
Xcode integration
三、jenkins JOB配置
3.1 job配置
自由風格
git地址
填寫xcode編譯參數
xcode參數
配置步驟可以逐步save,立即構建版本,看是否出錯。
嗯,我也來構建測試一下。
Results at '/Users/mac/.jenkins/jobs/Youxin/workspace/build/yxios.ipa' [Release-iphoneos] $ ditto -c -k --keepParent -rsrc /Users/mac/.jenkins/jobs/>Youxin/workspace/build/Release-iphoneos/yxios.app.dSYM /Users/mac/.jenkins/jobs/>Youxin/workspace/build/yxios-dSYM.zip Finished: SUCCESS
ok,next step!
四、shell到fir.im/蒲公英
上傳到fir.im
fir上傳環境搭建,請閱讀官方文檔
若出現安裝不了,請重新安裝你的ruby,brew等環境,可能用Xcode bata版的童鞋會遇到安裝不了的環境不問題
安裝完之後用fir命令上傳
fir b path/to/workspace -o path/to/output -w -C Release -t allTargets
fir-token
到jenkins中配置一下
增加步驟->Execute shell
fir build_ipa ${WORKSPACE} -o ${WORKSPACE}/build/ -p -T YOUR_FIR_TOKEN
I, [2015-08-12T16:11:18.669920 #72566] INFO -- : Build Success I, [2015-08-12T16:11:18.670328 #72566] INFO -- : I, [2015-08-12T16:11:19.202879 #72566] INFO -- : Publishing app....... I, [2015-08-12T16:11:19.202924 #72566] INFO -- : ? -------------------------------------------- ? I, [2015-08-12T16:11:19.278565 #72566] INFO -- : Fetching [email protected] uploading info...... I, [2015-08-12T16:11:19.435970 #72566] INFO -- : Uploading app...... I, [2015-08-12T16:11:19.865897 #72566] INFO -- : Updating devices info...... I, [2015-08-12T16:11:23.962306 #72566] INFO -- : ? -------------------------------------------- ? I, [2015-08-12T16:11:23.962349 #72566] INFO -- : Fetch app info from FIR.im I, [2015-08-12T16:11:24.100364 #72566] INFO -- : Publ
看到以上信息,說明我們的發布到fir平台成功。
上傳到蒲公英
蒲公英上傳請仔細參閱文檔1,文檔2
curl -F "file=@/tmp/example.ipa" -F "uKey={$uKey}" -F "_api_key={$apiKey}" -F "publishRange=2" http://www.pgyer.com/apiv1/app/upload
如果curl沒有安裝,請安裝一下
brew install curl
在我們執行fir.im上傳命令中增加上傳蒲公英的curl命令
curl -F "file=@${WORKSPACE}/build/yxios.ipa" \ -F "uKey=你的用戶key" \ -F "_api_key=你的apiKey" \ http://www.pgyer.com/apiv1/app/upload
保存->立即構件,waiting... 到Console output看打印log...
+ curl -F file=@/Users/mac/.jenkins/jobs/Youxin/workspace/build/yxios.ipa -F uKey=uKey -F >_api_key=aipkey http://www.pgyer.com/apiv1/app/upload % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1480k 0 0 100 1480k 0 481k 0:00:03 0:00:03 --:--:-- 481k 100 1480k 100 496 100 1480k 132 394k 0:00:03 0:00:03 --:--:-- 394k 100 1480k 100 496 100 1480k 132 394k 0:00:03 0:00:03 --:--:-- 394k {"code":0,"message":"","data":>{"appKey":"appkey","userKey":"ukey","appType":"1","appIsLastest":"1","appFileSize":"1515272","appName":"yxios","appVersion":"1.7","appVersionNo":"2.0.1","appBuildVersion":"1","appIdentifier":"com.mjc.yxios","appIcon":"b38bb809ebfa37dac81174a4e7716a26","appDescription":"","appUpdateDescription":"","appScreenshots":"","appShortcutUrl":"Dmfc","appCreated":"2015-08-12 16:58:20","appUpdated":"2015-08-12 16:58:20"}}Finished: SUCCESS
上傳成功...
快到fir.im 蒲公英上下載看看吧
安裝不了的,請在xcode中設置下證書,服務器環境安裝一下證書。
總結
jenkins是最近一兩周接觸的一個CI工具,可能測試/項目經理接觸的比較多一點,iOS這一塊,除了一些大廠,基本不會提自動化測試/部署/持續構件等,此文拋磚引玉,歡迎iOS/CI大神/測試大神來拍磚,本人也希望CI這一塊形成一系列blog,吸引更多的愛好者一起研究,推動iOS開發界CI的發展。
如果有任何纰漏請聯系我 @lp_馬建成
最後感謝,@fir.im @蒲公英 對本人部署測試此平台無私的幫助。
參考blogs
特別推薦
http://www.jianshu.com/p/a17167274463
http://www.jianshu.com/p/0515e2465c49
其他
http://www.cnblogs.com/itech/archive/2011/11/23/2260009.html
https://testerhome.com/topics/2762
https://testerhome.com/topics
http://blog.sina.com.cn/s/blog_63b4ee0d0101gdop.html
https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project
//mvn test
http://www.cocoachina.com/ios/20150428/11698.html
http://blog.csdn.net/xdrt81y/article/details/38755415
http://www.cnblogs.com/itech/archive/2011/11/23/2260009.html
平台文檔
http://blog.fir.im/fir_cli/
http://www.pgyer.com/doc/api#uploadApp
上傳環境
http://www.vettyofficer.com/2013/06/how-to-install-curl-in-mac-os-x.html
http://apple.stackexchange.com/questions/95855/how-to-install-curl-on-osx-with-brew