iOS持續(xù)集成—Jenkins(最新最全)

搭建Jenkins前,請確認mac系統(tǒng)上已經(jīng)搭建好了Java環(huán)境。
從零開始一步一步構(gòu)建严拒,遇到了很多坑,好在最終success了竖独。

一裤唠、 搭建Jenkins

1. 安裝Jenkins

官網(wǎng)上下載pkg安裝包

這里以jenkis-2.73.3.pkg包為例

安裝完成后,Safari可能會自動打開莹痢,如果沒有自動打開种蘸,打開瀏覽器,輸入http://localhost:8080
如果頁面提示不能連接服務(wù)器的錯誤竞膳,重啟電腦航瞭。然后再輸入http://localhost:8080進入登錄頁面。
根據(jù)提示坦辟,找到/Users/Shared/Jenkins/Home/ 這個目錄刊侯,找到secrets文件,顯示簡介长窄,設(shè)置所有人都可以讀與寫的權(quán)限滔吠,并找到initialAdminPassword文件,同樣放開權(quán)限挠日,復(fù)制出密碼疮绷,登錄進去,一路安裝過來嚣潜,輸入用戶名冬骚、密碼、郵件等懂算。最后點擊Save and Finish只冻。

注意:如果安裝之后發(fā)現(xiàn)密碼忘記了,從initialAdminPassword文件中復(fù)制輸入也錯誤计技,試了很多方法也不管用喜德,那就卸載重裝Jenkis然后重啟電腦吧。

2. 拷貝文件

2.1

將/Users/用戶名/Library的MobileDevice文件夾拷貝到/Users/Shared/Jenkins/Library下

注意:是將MobileDevice這個文件夾拷貝過去垮媒,而不是MobileDevice里的文件舍悯,/Users/Shared/Jenkins/Library 目錄下是沒有MobileDevice這個文件夾航棱,所以先創(chuàng)建一個MobileDevice文件夾。

在終端輸入:

sudo mkdir /Users/Shared/Jenkins/Library/MobileDevice
sudo cp -r /Users/xxx/Library/MobileDevice/ /Users/Shared/Jenkins/Library/MobileDevice/

注意:曾遇到/Users/xxx/Library/下沒有MobileDevice文件夾萌衬,原來是新機上沒有安裝Xcode饮醇。

2.2

將/Users/用戶名/Library/Keychains/下的login.keychain及l(fā)ogin.keychain-db這兩個文件拷貝到/Users/Shared/Jenkins/Library/Keychains文件夾下面

注意:Mac OS 10.12以下的沒有l(wèi)ogin.keychain-db這個文件,只需要拷貝login.keychain文件秕豫。

在終端輸入:

cd /Users/Shared/Jenkins/Library/
sudo mkdir Keychains
sudo cp /Users/xxx/Library/Keychains/login.keychain ./Keychains/
sudo cp /Users/xxx/Library/Keychains/login.keychain-db ./Keychains/

再將這個login.keychain拷貝到桌面上

在終端輸入:

sudo cp /Users/jiekangwei/Library/Keychains/login.keychain ~/Desktop/

注意:如果/Users/xxx/Library/Keychains/目錄下沒有l(wèi)ogin.keychain這個文件朴艰,就復(fù)制login.keychain-db文件到指定目錄,然后將復(fù)制在桌面上的該文件改后綴為.keychain混移。

3. 鑰匙串權(quán)限祠墅、~/Library權(quán)限以及電腦用戶管理權(quán)限

3.1

打開鑰匙串,找到相應(yīng)的證書

右鍵密鑰顯示簡介歌径,在訪問控制那一項里勾選允許所有應(yīng)用程序訪問此項目饵隙,并存儲更改。

3.2

找到Library資源庫文件夾沮脖,設(shè)置共享與訪問權(quán)限,everyone讀與寫都可以

3.3

進入mac系統(tǒng)偏好設(shè)置 — 用戶與群組 — 其他用戶 — jenkins 芯急,勾選允許用戶管理這臺電腦勺届,并右鍵選擇高級選項,將名字改為jenkins

4. Jenkins插件及系統(tǒng)設(shè)置

進入管理插件娶耍,在可選插件里所有關(guān)鍵字免姿,下載安裝插件Keychains and Provisioning ProfilesManagementXcode integration

4.1

選取拷 在桌上login.keychain以及項 相對應(yīng)的Provisioning Profile 并upload

注意:開發(fā)證書和provision profile 一定要對應(yīng)正確,不然命令行打包會認證不了而失敗

password 一定要填寫正確的鑰匙串的密碼

Code Signing Identity 是從鑰匙 找到相應(yīng)的證書榕酒,然后顯示簡介復(fù)制 來胚膊,這 Identities 少要填 兩項,是因為這 放 個的話后 的設(shè)置 Code Signing Identity 能 動對應(yīng)上想鹰。

Provisioning Profiles Directory Path 這 項 填寫/Users/用戶名/Library/ MobileDevice/Provisioning Profiles

注意:路徑里Provisioning Profiles是Provisioning\ Profiles

點擊Save

4.2

安裝完Xcode integration后進 系統(tǒng)設(shè)置紊婉。

Xcode Builder

填寫鑰匙串密碼

5. 新建

5.1

填寫名字,選擇構(gòu)建自由風(fēng)格辑舷,點擊ok

進入Project喻犁,進入配置

5.2

General

項目名稱,這里可以和git項目名稱一樣何缓,也可以另起一個名稱肢础。

5.3

源碼管理

選擇git,然后在Repository URL 上填寫git倉庫地址

選擇add

選擇SSH Username with private key
Username 為上傳到git的用戶名碌廓,Private Key從id_rsa文件里復(fù)制出來

5.4

構(gòu)建觸發(fā)器传轰,可選填

5.5

構(gòu)建環(huán)境

選擇Keychains andProvisioning Profiles ManagementMobile Provisioning Profiles

Code Signing Identity 第一次不能自動顯示出來沒關(guān)系,保存谷婆,然后第二次進來就自動選上了慨蛙。

5.6

構(gòu)建

有兩種打包方式辽聊,一是用Xcode打包,而是用Shell腳本打包股淡,當Xcode版本為9或者以上身隐,應(yīng)該使用Shell腳本打包。

因為 Xcode 9 默認不允許訪問鑰匙串的內(nèi)容唯灵,必須要設(shè)置 allowProvisioningUpdates 才會允許贾铝,但是由于 Xcode integration 插件封閉,并不能對其進行修改加上這個屬性埠帕,所以使用 Shell 腳本代替插件垢揩。

5.6.1

這里先介紹Xcode打包,項目使用的是Xcode 8.1

General build settings

這里Target請于Xcode項目中Target的名字對應(yīng)
Clean before build設(shè)置為YES
Configuration選擇Release)
Output directory為.ipa的輸出路徑敛瓷,可選填

Code signing & OS X keychain options

teamId 為對應(yīng)證書括號里面有叁巨,如果沒找到,請在蘋果開發(fā)網(wǎng)站登陸進去呐籽,從Membership上查看锋勺。選擇Unlock Keychain,填寫鑰匙串密碼

Advanced Xcode build options

Xcode Schema Files 填寫Xcode項目的schema
因為項目含有Workspace狡蝶,所以填寫Xcode Workspace File庶橱,填寫該項目xcworkspace文件的絕對路徑
Build output directory 填寫${WORKSPACE}/build/ ,這里注意是大括號

打開工程贪惹,mange schemes苏章,勾選項目schemes對應(yīng)的shared,該scheme為填寫的Xcode Schema Files的內(nèi)容

ok奏瞬,點擊保存枫绅,使用Xcode構(gòu)建配置完畢

5.6.2

選擇Execute shell 打包

command 寫入腳本:

xcodebuild clean -workspace 工程名稱.xcworkspace -scheme 工程名稱 -configuration Release

xcodebuild archive -workspace 工程名稱.xcworkspace -scheme 工程名稱 -archivePath 工程名稱.xcarchive

xcodebuild -exportArchive -archivePath 工程名稱.xcarchive -exportOptionsPlist /Users/用戶名/ExportOptions.plist -allowProvisioningUpdates -exportPath ./

ExportOptions.plist 注意大小寫,先打包工程硼端,將ExportOptions.plist文件拷貝到/Users/用戶名/或者指定的目錄并淋,記得腳本中/Users/用戶名/ExportOptions.plist 對應(yīng)的是該文件的路徑。

Next 珍昨,然后Export

6. 上傳

這里把項目上傳到fir.im平臺為例

之前選擇使用命令行

但遺憾的是用終端安裝fir-cli總是失敗预伺,于是就選擇使用fir.im插件

這里選擇使用fir.im插件, 進入 官網(wǎng)下載曼尊,下載jenkins插件

然后進入Jenkins酬诀,選擇插件管理 — 高級

選擇下載好的fir-plugin-1.9.5.hpi,上傳并安裝完后

進入項目的配置頁面骆撇,在構(gòu)建后操作里選擇Upload to fir.im瞒御,填寫fir.im token

好了,點擊保存神郊,立即構(gòu)建吧

如果構(gòu)建時后臺打印出以下信息肴裙,恭喜你趾唱,你構(gòu)建成功了

二、配置Jenkins錯誤

1蜻懦、 拷貝文件錯誤

Failed to copy /Users/Shared/Jenkins/Home/kpp_upload/xxxx.mobileprovision to /Users/xxx/Library/MobileDevice/Provisioning Profiles/xxxx.mobileprovision

解決:文件拷貝失敗甜癞。1.查看Library讀寫權(quán)限是否開放;2. 查看系統(tǒng)管理 — Keychains and Provisioning Profiles Management宛乃,查看Provisioning Profiles Directory path 是否有誤

2悠咱、 證書文件找不到

Check dependencies Code Sign error: No matching provisioning profile found: Your build settings specify a provisioning profile with the UUID “75025357-245d-448b-9343-96148a0xxxxx”, however, no such provisioning profile was found.

解決:將/Users/管理員用戶名/Library下的MobileDevice文件夾拷貝到/Users/Shared/Jenkins/Library下面

security: SecKeychainUnlock login.keychain: The user name or passphrase you entered is not correct. FATAL: Unable to unlock the keychain.

解決:確認鑰匙串密碼是正確的

4、 pod沒有權(quán)限

/Users/xxx/workspace/xxxx/Pods/Target Support Files/Pods-xxxx/Pods-xxxx-resources.sh: line 7: /Users/xxx/workspace/xxxx/Pods/resources-to-copy-DiscoverPanjin.txt: Permission denied

解決:在終端打開項目目錄并輸入 sudo chmod 777 Pods

5征炼、 使用fir插件上傳失敗

ERROR: Can not found mapping or dysm file in /Users/Shared/Jenkins/Home/jobs/xxxx/workspace. Deployment failed : Error while get details for update id = xxxxx Build step 'Upload to fir.im' marked build as failure

解決:fir插件版本過低析既,使用最新fir插件試試

5、使用命令行上傳失敗

fir p/Users/Shared/Jenkins/Home/jobs/xxx/workspace/build/xxx.ipa -T 4dc6d4c3ebe1969b3c76353514xxxxx /Users/Shared/Jenkins/tmp/jenkins3233517671203652013.sh: line 2: fir: command not found Build step 'Execute shell' marked build as failure

解決:沒有安裝fir-cli命令

6谆奥、

Will not set default: file /Users/Shared/Jenkins/Library/Keychains/login.keychain-db is owned by UID=0, but we have UID=262 security: SecKeychainSetDomainDefault user: write permissions error

解決:進入mac 系統(tǒng)偏好設(shè)置 — 用戶與群組 — 其他用戶 — jenkins 眼坏,勾選允許用戶管理這臺電腦

7、

FATAL: Failed to mkdirs: /Users/xxx/Desktop/ipa java.io.IOException: Failed to mkdirs: /Users/xxx/Desktop/ipa

解決:Output directory 路徑錯誤

8酸些、

FATAL: Build directory does not exist at /$(WORKSPACE)/build. Potential configuration issue. Build step 'Xcode' marked build as failure

解決:Build output directory 填寫錯誤宰译,正確為${WORKSPACE}/build

9、

== Available schemes [workspace] $ /usr/bin/xcodebuild -list -workspace /Users/xxx/workspace/xxxx.xcworkspace xcodebuild: error: '/Users/xxx/workspace/xxxx.xcworkspace' does not exist.

解決:Xcode Workspace File 路徑錯誤

10魄懂、

rror Domain=IDEProfileLocatorErrorDomain Code=1 "No profiles for 'xxxxxxx' were found" UserInfo={NSLocalizedDescription=No profiles for 'xxxxxxx' were found, NSLocalizedRecoverySuggestion=Xcode couldn't find any iOS Ad Hoc provisioning profiles matching 'xxxxxxx'. Automatic signing is disabled and unable to generate a profile. To enable automatic signing, pass -allowProvisioningUpdates to xcodebuild.

解決:打包工程導(dǎo)出ipa時選擇手動選擇證書

11囤屹、

+ xcodebuild -exportArchive -archivePath /xxx.xcarchive -exportPath -exportOptionsPlist /Users/xxx/exportOptionsPlist.plist
xcodebuild: error: The flag -exportOptionsPlist is required when specifying -exportArchive.
Build step 'Execute shell' marked build as failure

解決:拷貝到指定路徑的ExportOptions.plist 名稱大小寫錯誤

12、

create and update profiles, app IDs, and certificates. For manually signed targets, xcodebuild will download missing or updated provisioning profiles. Requires a developer account to have been added in Xcode's Accounts preference pane. -allowProvisioningDeviceRegistration Allow xcodebuild to register your destination device on the developer portal if necessary. This flag only takes effect if -allowProvisioningUpdates is also passed. Build step 'Xcode' marked build as failure

解決:腳本上缺少allowProvisioningUpdates這一句

13逢渔、

$ /usr/bin/xcodebuild -scheme xxxx -workspace /Users/用戶名/workSpace/xxxx/xxx.xcworkspace -configuration Release clean archive -archivePath "/Users/Shared/Jenkins/Home/workspace/xxx/build/xxxx.xcarchive" "BUILD_DIR=/Users/Shared/Jenkins/Home/workspace/xxx/build/" DEVELOPMENT_TEAM=EFL2T3NT3W -exportArchive -exportPath /Users/Shared/Jenkins/Home/workspace/xxx/build/ -exportOptionsPlist /Users/xxx/options.plist
xcodebuild: error: The flag -scheme cannot be specified along with -exportArchive.

或者

[iOS Panjin] $ /bin/sh -xe /Users/Shared/Jenkins/tmp/jenkins410183735701877848.sh
+ echo '================= Clean一下 ================='
================= Clean一下 =================
+ xcodebuild clean -workspace .xcworkspace -configuration -target
xcodebuild: error: If you specify a workspace then you must also specify a scheme.  Use -list to see the schemes in this workspace.
Build step 'Execute shell' marked build as failure
Build step 'Xcode' marked build as failure

或者:

[iOS xxx] $ /bin/sh -xe /Users/Shared/Jenkins/tmp/jenkins8239787762841783385.sh
+ xcodebuild clean -workspace .xcworkspace -scheme -configuration
xcodebuild: error: '.xcworkspace' does not exist.
Build step 'Execute shell' marked build as failure

或者:

+ xcodebuild -exportArchive -archivePath /xxx.xcarchive -exportOptionsPlist /Users/xxx/ExportOptions.plist -allowProvisioningUpdates -exportPath ./
error: archive not found at path '/xxx.xcarchive'
Build step 'Execute shell' marked build as failure

解決:用腳本構(gòu)建時,腳本輸寫有誤

14乡括、

+ xcodebuild -exportArchive -archivePath /DiscoverPanjin.xcarchive -exportOptionsPlist /Users/xunlusheji/exportOptionsPlist.plist -allowProvisioningUpdates -exportPath ./
error: Couldn't load -exportOptionsPlist: The file “exportOptionsPlist.plist” couldn’t be opened because there is no such file.

Error Domain=NSCocoaErrorDomain Code=260 "The file “exportOptionsPlist.plist” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Users/xxxx/exportOptionsPlist.plist, NSUnderlyingError=0x7fd745d91140 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

** EXPORT FAILED **

Build step 'Execute shell' marked build as failure

解決:缺少ExportOptions.plist

15肃廓、

+ xcodebuild -exportArchive -archivePath xxxx.xcarchive -exportOptionsPlist /Users/xxx/ExportOptions.plist -allowProvisioningUpdates -exportPath ./
error: archive not found at path '/Users/Shared/Jenkins/Home/workspace/xxx/xxx.xcarchive'
** EXPORT FAILED **

Build step 'Execute shell' marked build as failure

解決: /Users/Shared/Jenkins/Home/workspace/ 下.xcarchive 文件名稱有誤,或者.xcarchive文件路徑有誤

16诲泌、

Error Domain=IDECodesignResolverErrorDomain Code=1 "No certificate for team 'xxxxx' matching 'DB8C944F71D475DE773696BD637xxxxxxx' found" UserInfo={IDEProvisioningError_UserInfoKey_IDEProvisioningErrorSpecifier=DB8C944F71D475DE773696BD6374C5xxxxx, NSLocalizedDescription=No certificate for team 'xxxxx' matching 'DB8C944F71D475DE773696BD6374C5BBxxxxxxx' found, NSLocalizedRecoverySuggestion=Specify a different signing certificate for "signingCertificate" in your Export Options property list., IDEProvisioningError_UserInfoKey_IDEProvisioningErrorTeam=<IDEProvisioningBasicTeam 0x7fee800853e0: teamID: xxxxxx, teamName: (null)>, IDEProvisioningError_UserInfoKey_IDEProvisioningErrorPlatform=com.apple.platform.iphoneos, IDEProvisioningError_UserInfoKey_IDEProvisioningErrorAction=5}

解決:keychains下的provisioning profile 對應(yīng)不上 certificate證書盲赊,把鑰匙串相應(yīng)的證書刪掉,重新從蘋果商店下載證書和provisioning profile敷扫,在Jenkis —系統(tǒng)設(shè)置— Keychains and Provisioning Profiles Management插件里全部刪除哀蘑,執(zhí)行前文 2、拷貝文件 操作葵第,然后upload新的login.keychain和provisioning profile

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末绘迁,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子卒密,更是在濱河造成了極大的恐慌缀台,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,755評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件哮奇,死亡現(xiàn)場離奇詭異膛腐,居然都是意外死亡睛约,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,305評論 3 395
  • 文/潘曉璐 我一進店門哲身,熙熙樓的掌柜王于貴愁眉苦臉地迎上來辩涝,“玉大人,你說我怎么就攤上這事勘天≌” “怎么了?”我有些...
    開封第一講書人閱讀 165,138評論 0 355
  • 文/不壞的土叔 我叫張陵误辑,是天一觀的道長沧踏。 經(jīng)常有香客問我,道長巾钉,這世上最難降的妖魔是什么翘狱? 我笑而不...
    開封第一講書人閱讀 58,791評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮砰苍,結(jié)果婚禮上潦匈,老公的妹妹穿的比我還像新娘。我一直安慰自己赚导,他們只是感情好茬缩,可當我...
    茶點故事閱讀 67,794評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著吼旧,像睡著了一般凰锡。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上圈暗,一...
    開封第一講書人閱讀 51,631評論 1 305
  • 那天掂为,我揣著相機與錄音,去河邊找鬼员串。 笑死勇哗,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的寸齐。 我是一名探鬼主播欲诺,決...
    沈念sama閱讀 40,362評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼渺鹦!你這毒婦竟也來了扰法?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,264評論 0 276
  • 序言:老撾萬榮一對情侶失蹤毅厚,失蹤者是張志新(化名)和其女友劉穎迹恐,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,724評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡殴边,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年憎茂,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片锤岸。...
    茶點故事閱讀 40,040評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡竖幔,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出是偷,到底是詐尸還是另有隱情拳氢,我是刑警寧澤,帶...
    沈念sama閱讀 35,742評論 5 346
  • 正文 年R本政府宣布蛋铆,位于F島的核電站馋评,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏刺啦。R本人自食惡果不足惜留特,卻給世界環(huán)境...
    茶點故事閱讀 41,364評論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望玛瘸。 院中可真熱鬧蜕青,春花似錦、人聲如沸糊渊。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,944評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽渺绒。三九已至贺喝,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間宗兼,已是汗流浹背躏鱼。 一陣腳步聲響...
    開封第一講書人閱讀 33,060評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留针炉,地道東北人。 一個月前我還...
    沈念sama閱讀 48,247評論 3 371
  • 正文 我出身青樓扳抽,卻偏偏與公主長得像篡帕,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子贸呢,可洞房花燭夜當晚...
    茶點故事閱讀 44,979評論 2 355

推薦閱讀更多精彩內(nèi)容