本文以本地和Git為例,結(jié)合CocoaPods叔磷,簡(jiǎn)單介紹了如何用jenkins來(lái)進(jìn)行CI編譯并上傳蒲公英和Fir生成相應(yīng)二維碼的流程拢驾。
準(zhǔn)備工作
首先,去Jenkins主頁(yè)下載war包進(jìn)行本地編譯改基,網(wǎng)址為:https://jenkins.io/index.html
這里,筆者以LTS Release的2.7.2.war包為例
下好了war包后寥裂,運(yùn)行War包嵌洼,并設(shè)置其端口號(hào),命令如下:
java -jar jenkins.war --httpPort=8888
運(yùn)行后命令行如下圖所示:
http://localhost:8888
之后根據(jù)頁(yè)面提示封恰,輸入密碼并且創(chuàng)建賬戶(hù)后麻养,即可打開(kāi)Jenkins主頁(yè)。
配置工作
配置工作里主要進(jìn)行插件的安裝诺舔,插件安裝方法為:
系統(tǒng)管理 -->管理插件鳖昌,選可選插件,選擇對(duì)應(yīng)插件后點(diǎn)擊直接安裝即可低飒。
以iOS的持續(xù)集成為例许昨,推薦安裝的插件為:
- build timeout plugin
This plugin allows builds to be automatically terminated after the specified amount of time has elapsed. - Checkstyle Plug-in
This plug-in collects the Checkstyle analysis results of the project modules and visualizes the found warnings. - Credentials Binding Plugin
Allows credentials to be bound to environment variables for use from miscellaneous build steps. - description setter plugin
This plugin sets the description for each build, based upon a RegEx test of the build log file. - Email Extension Plugin
This plugin is a replacement for Jenkins's email publisher - Git Changelog
Plugin creating JIRA filter URL based on commit messages containing JIRA ticket keys in the GIT history - GitHub Organization Folder Plugin
Scan entire GitHub organization for buildable branches and pull requests, in repositories. See Pipeline as Code solution page for more details. - Gitlab Hook Plugin
Enables Gitlab web hooks to be used to trigger SMC polling on Gitlab projects - GitLab Plugin
This plugin integrates GitLab to Jenkins by faking a GitLab CI Server. - Gradle Plugin
This plugin allows Jenkins to invoke Gradle build scripts directly - HTML Publisher plugin
This plugin publishes HTML reports. - Keychains and Provisioning Profiles Management
This plugin integrates management of keychain and provisioning files for iOS and OSX projects. - Log Parser Plugin
Parse the console output and highlight error/warning/info lines. - Pipeline
A suite of plugins that lets you orchestrate automation, simple or complex. See Pipeline as Code with Jenkinsfor more details. - Post-Build Script Plug-in
PostBuildScript makes it possible to execute a set of scripts at the end of the build. - Project Description Setter
Set the project description from a file in the workspace - Publish Over FTP
Send build artifacts over FTP - Subversion Plug-in
This plugin adds the Subversion support (via SVNKit) to Jenkins. - Timestamper
Adds timestamps to the Console Output. - Workspace Cleanup Plugin
This plugin deletes the project workspace after a build is finished. - Xcode integration
This plugin provides builders to build xcode projects, invoke agvtool and package .ipa files
創(chuàng)建任務(wù)
在Jenkins主頁(yè)點(diǎn)擊新建,輸入Job名后褥赊,選擇第一項(xiàng):構(gòu)建一個(gè)自由風(fēng)格的軟件項(xiàng)目
之后進(jìn)入配置頁(yè)面糕档,按照下圖來(lái)進(jìn)行配置:
配置管理配置部分按下圖填寫(xiě):
CocoaPods配置
選擇構(gòu)建-->增加構(gòu)建步驟-->Execute Shell,再對(duì)應(yīng)pod的代碼填寫(xiě)進(jìn)去:
Command里必須要的是pod install
拌喉,其他視項(xiàng)目結(jié)構(gòu)而定速那。例如筆者的項(xiàng)目由于podfile文件在子目錄之中,所以先執(zhí)行CD [子目錄名]
進(jìn)入子目錄再執(zhí)行尿背。
Warning:
- 在Jenkins中設(shè)置CocoaPods配置之前請(qǐng)務(wù)必保證本地CocoaPods可以正常工作端仰。這里默認(rèn)你的CocoaPods已經(jīng)執(zhí)行過(guò)了
pod setup
這些步驟了。 - CocoaPods的Execute Shell一定要在XCode配置之前執(zhí)行田藐。(點(diǎn)擊左側(cè)的拖動(dòng)bar荔烧,可以自由調(diào)整插件順序)
- 目前Jenkins上雖然有CocoaPods的插件吱七,但是功能有限,不推薦使用
XCode General配置
先進(jìn)行添加:選擇構(gòu)建-->增加構(gòu)建步驟-->XCode
General Build Settings
在target處填寫(xiě)XCode項(xiàng)目的target名稱(chēng)鹤竭。如果不知道名稱(chēng)踊餐,去項(xiàng)目目錄下運(yùn)行xcodebuild -list
進(jìn)行查看;
Configuration設(shè)置為Debug或者Release诺擅,取決于你想要什么樣的版本市袖;
ipa filename pattern:可以定制ipa的名稱(chēng),例如yourIPAname_${VERSION}_${BUILD_DATE}
Output directory設(shè)置ipa的路徑烁涌。
配置證書(shū)
Code signing & OS X keychain options設(shè)置如下:
Code Sign Identity填寫(xiě)證書(shū)的名稱(chēng)(請(qǐng)查看你的Keychain里對(duì)應(yīng)iPhone Developer證書(shū)的名稱(chēng)苍碟,包括括號(hào)里的內(nèi)容)
unlock Keychain,在Keychain Path里填入在項(xiàng)目中倒入的開(kāi)發(fā)者證書(shū)的keychain撮执。如果不知道在哪兒微峰,可以試試:
default : ${HOME}/Library/Keychains/login.keychain
Password是你的登陸密碼
XCode 高級(jí)設(shè)置
XCode Schema File:如果不知道名稱(chēng),去項(xiàng)目目錄下運(yùn)行xcodebuild -list
進(jìn)行查看抒钱;
SYMROOT:填寫(xiě)你想設(shè)置的SYMROOT蜓肆,例如${WORKSPACE}/build/
Custom xcodebuild arguments:XCode配置參數(shù),可以參考下圖的設(shè)置
XCode Workspace File:如果需要運(yùn)行workspace谋币,請(qǐng)選擇項(xiàng)目下對(duì)應(yīng)的*. xcworkspace文件
XCdoe Project Directory:填寫(xiě)項(xiàng)目路徑
XCode Project File:填寫(xiě)Project文件所在路徑
開(kāi)發(fā)者證書(shū)導(dǎo)入
XCode此時(shí)應(yīng)該導(dǎo)入開(kāi)發(fā)者證書(shū):
- 從蘋(píng)果開(kāi)發(fā)者官網(wǎng):官網(wǎng)地址,導(dǎo)入Certificates和Provisioning Profiles證書(shū)或密鑰:
Apple Developer
應(yīng)該保證XCode的General窗口箭頭位置沒(méi)有黃色的驚嘆號(hào):
集成蒲公英發(fā)布系統(tǒng):
點(diǎn)擊增加構(gòu)建步驟-->Execute shell仗扬,創(chuàng)建腳本窗口:
在腳本里填寫(xiě)如下格式代碼:
curl -F "file=@${WORKSPACE}/ipa/helloJenkins.ipa" -F "uKey=xxxx" -F "_api_key=xxx" https://www.pgyer.com/apiv1/app/upload
其中,file是ipa文件的路徑蕾额,記得要帶@早芭;uKey與F_api_key是蒲公英系統(tǒng)上的userKey與apiKey,蒲公英官網(wǎng)注冊(cè)好后填寫(xiě)完全即可诅蝶。
選擇增加構(gòu)建后操作步驟--> Set Build Description,如下圖所示:
在Description中填寫(xiě)Image的對(duì)應(yīng)地址即可:
點(diǎn)擊OK退个,編譯即可。然后進(jìn)入Console頁(yè)面去查看调炬。
成功后應(yīng)該如下圖所示:
集成fir.im發(fā)布系統(tǒng)
集成fir比集成蒲公英更加簡(jiǎn)單语盈,因?yàn)楣俜接衘enkins插件。直接安裝后配置其apiKey即可缰泡。
參考fir官網(wǎng)對(duì)其的介紹頁(yè)面
集成Git
取消掉XCode對(duì)應(yīng)設(shè)置
如果確定要通過(guò)Git來(lái)構(gòu)建刀荒,先取消掉之前的Advanced Xcode build options步驟,方法是清除Advanced Xcode build options內(nèi)部的所有配置
更改源碼管理
隨后匀谣,回到源碼管理照棋,將選項(xiàng)由none改為Git,填入Git項(xiàng)目地址武翎。這里以public項(xiàng)目為例,所有下面的credentials不用填寫(xiě)溶锭。如果是private宝恶,則需要填寫(xiě)git的用戶(hù)名密碼。
參數(shù)化構(gòu)建
想要達(dá)到根據(jù)具體分支構(gòu)建的目的,需要添加對(duì)應(yīng)插件Git Parameter Plugin
之后進(jìn)入配置頁(yè)面:
在添加參數(shù)頁(yè)面中設(shè)置 Git Parameter
之后按照下圖所示進(jìn)行設(shè)置:
之后要在下面的 源碼管理 Git配置頁(yè)面中Branch的對(duì)應(yīng)字段填寫(xiě)你在Git Parameter中Name上所寫(xiě)的名字垫毙,如下所示:
希望小文能給各位的工作帶來(lái)幫助霹疫!