Jenkins是個比較方便持續(xù)集成的工具苦蒿,簡單記錄一下利用Jenkin拉取SVN的iOS代碼殴胧,并且打包上傳到蒲公英(fir.im類似)的過程。安卓只需要安裝對應的插件就可以佩迟⊥爬模可以實現(xiàn)定時打包發(fā)布任務,方便自動化管理报强【逆ⅲ考慮到現(xiàn)在代碼基本往Git上遷移,在第八步給出快捷遷移SVN代碼到Git的方法秉溉。
一力惯、安裝Jenkins
下載pkg文件
安裝后會自動打開http://localhost:8080
第一次的初始密碼在initialAdminPassword
文件中
/Users/Shared/Jenkins/Home/secrets/initialAdminPassword
也可以使用Homebrew
安裝
brew install jenkins
$ brew update && brew outdated jenkins
$ brew cask install java
$ ln -sfv /usr/local/opt/jenkins/*.plist ~/Library/LaunchAgents
$ sudo cp -fv /usr/local/opt/jenkins/*.plist /Library/LaunchDaemons
$ sudo chown `whoami` /Library/LaunchDaemons/homebrew.mxcl.jenkins.plist
參考installing-jenkins-os-x-homebrew
二、選擇安裝插件
2.1 需要安裝的插件:
Xcode integration
Keychains and Provisioning Profiles Management
安裝完成后我們重啟下jenkins召嘶,重新加載下插件父晶。可以滑到最底下勾選重啟弄跌,或者也可以在地址欄輸入http://localhost:8080/restart
重啟之后應該要輸入用戶名和密碼甲喝,把剛剛注冊的用戶名密碼輸入進去。還有一個重要的步驟碟绑,我們先給Jenkins用戶管理員的權限俺猿,避免后續(xù)的訪問問題茎匠。系統(tǒng)偏好設置->用戶與群組->點開鎖,然后在Jenkins用戶下勾選“允許用戶管理這臺電腦”押袍。到這步最好給Jenkins用戶設置一個密碼诵冒,便于后期檢查是否Jenkins配置錯誤或者是檢查代碼錯誤。
三谊惭、創(chuàng)建一個item
四汽馋、設置基本配置
五、配置SVN
5.1 連接SVN代碼庫
六圈盔、設置打包的簽名
這里需要打開 Keychains
插件
Keychains and Provisioning Profiles Management
上傳login.keychain
文件豹芯,證書和對應的profile
文件
login.keychain
文件路徑:
~/Library/Keychains
其中l(wèi)ogin.keychain-db可以改成login.keychain,然后上傳
如果是用Pod管理的驱敲,需要打開Scheme共享:
沒有打開共享的路徑:
$ /Users/developer/Library/Keychains/login.keychain
我這邊是用Pod管理的铁蹈,打開Scheme共享的路徑:
$ /Users/Shared/Jenkins/Library/Keychains/login.keychain
在Jenkins的Xcode模板配置如下:
通用路徑:
${HOME}/Library/Keychains/login.keychain
6.1 證書
Keychain password
對應的密碼可以在鑰匙串中查看:
6.2 描述文件Profiles
把Provisioning Profiles
文件放到Jenkins/Library/MobileDeviece/Provision Profiles
文件夾中
然后配置簽名和鑰匙串的選項
6.3 設置Xcode integration
面板
七、上傳到蒲公英
腳本代碼:
curl -F "file=@${WORKSPACE}/build/ipa/${JOB_NAME}@${VERSION}@${BUILD_DATE}.ipa"
-F "uKey=uKey" -F "_api_key=_api_key" https://www.pgyer.com/apiv1/app/upload
注:對于Cocoapods
項目众眨,需要設置schemes
為Shared
握牧,不然可能因為找不到scheme
報錯
注意點
1、Jenkins 安裝成功后,會創(chuàng)建一個Jenkins用戶娩梨,而Jenkins的工作區(qū)間默認是在/用戶/共享/Jenkins/Home/jobs
目錄下沿腰,可以用Finder-->前往
進入。
2狈定、Jenkins目錄下的文件夾的讀寫權限只對Jenkins用戶開放颂龙,所以后面apple證書等必須在Jenkins用戶下安裝,項目的ipa導出也得在Jenkins用戶下操作纽什。(或者用管理員權限修改該目錄針對用戶的權限)
3措嵌、Jenkins的使用是每一個用戶都可以使用,所以有可能導致構(gòu)建版本的時候報錯稿湿,還是老老實實在Jenkins用戶下操作吧铅匹。
常用命令
1)我們先把jenkins停掉押赊,執(zhí)行:
sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist
3.第三個坑:打包iOS有pod的項目饺藤,shell
執(zhí)行pod install
時,提示pod command not found
流礁,這個需要在shell
第一行加上 bin/bash -l
就行了涕俗,所以最終是這樣:
!/bin/bash -l
export LANG=en_US.UTF-8
pod install --verbose --no-repo-update
- 第四個坑:有pod的項目可能提示schema找不到的問題,需要用xcode打開一次.xcworkspace就好了神帅,或者在shell pod install之后下加上 open x.xcworkspace
常見錯誤
1.Cocoapods打包問題Jenkins:”ResourceRules.plist: cannot read resources” error after Xcode 6.1
error: /usr/bin/codesign --force --preserve-metadata=identifier,entitlements,
resource-rules --sign iPhone Distribution: Certificate--resource-rules=/var/folders/ph/2y4lb27j1zx6lcp3htvhnlbm000087/T/ctBXHIqC3V/Payload/ProjectName
.app/ResourceRules.plist --entitlements
/var/folders/ph/2y4lb27j1zx6lcp3htvhnlbm000087/T/ctBXHIqC3V/entitlements_plistUx80j3Iz
/var/folders/ph/2y4lb27j1zx6lcp3htvhnlbm000087/T/ctBXHIqC3V/Payload/ProjectName.app failed with error 1.
Output: Warning: usage of --preserve-metadata with option "resource-rules" (deprecated in Mac OS X >= 10.10)!
Warning: --resource-rules has been deprecated in Mac OS X >= 10.10!
/var/folders/ph/2y4lb27j1zx6lcp3htvhnlbm000087/T/ctBXHIqC3V/Payload/ProjectName.app/ResourceRules.plist: cannot read resources
解決方法:
在Custom xcodebuild arguments
處填入:
CODE_SIGN_RESOURCE_RULES_PATH=$(SDKROOT)/ResourceRules.plist
錯誤2 :
Code Sign error: No matching provisioning profile found: Your build settings specify a provisioning profile with the UUID “dc5a6f0d-5d0e-4680-9d07-248d78b4d576”, however, no such provisioning profile was found.
解決方法:
檢查后發(fā)現(xiàn)SVN上的Code Sign配置并沒有和本地的一致再姑,確認后,提交SVN后解決
錯誤3 :Cocoapods打包
error: /usr/bin/codesign --force --preserve-metadata=identifier,entitlements,resource-rules --sign iPhone Distribution: Certificate--resource-rules=/var/folders/ph/2y4lb27j1zx6lcp3htvhnlbm000087/T/vDWiCo9Pi6/Payload/ProjectName.app/ResourceRules.plist
--entitlements /var/folders/ph/2y4lb27j1zx6lcp3htvhnlbm000087/T/vDWiCo9Pi6/entitlements_plistUcV_4_yn /var/folders/ph/2y4lb27j1zx6lcp3htvhnlbm000087/T/vDWiCo9Pi6/Payload/ProjectName.app failed with error 1. Output: Warning: usage of
--preserve-metadata with option "resource-rules" (deprecated in Mac OS X >= 10.10)!
解決方法:
步驟1
nomadshenzhen
步驟2
--resource-rules has been deprecated in mac os x >= 10.10
在Xcode Building Setting的Code Signing Resource Rules Path 中添加
$(SDKROOT)/ResourceRules.plist
錯誤4: xcodebuild: error: 'APP.xcworkspace' does not exist
Choose Product > Scheme > Manage Schemes.
Share your scheme:
- 缺少scheme
xcodebuild: error: The project named “Foo” does not contain a scheme named “Bar”. The “-list” option can be used to find the names of the schemes in the project.
解決辦法:
The root cause is that the default behavior of Schemes is to keep schemes ‘private’ until they are specifically marked as shared. In the case of a command-line initiated build, the Xcode UI never runs and the xcoderun tool doesn’t have its own cache of Schemes to work with.
To your schema be visible for command-line build you must mark it as a shared scheme.
Choose Scheme > Manage Schemes (from the Product Menu).
Ensure the ‘Shared’ box is checked for that scheme
A new .xcscheme file has been created in your project at
WorkspaceName.xcworkspace/xcshareddata/xcschemes.
Commit this file to your repository
八找御、SVN代碼遷移到GIt
方法:
使用Git命令,把SVN上的代碼和提交記錄clone到本地元镀,然后提交到Git上绍填。
主要命令
git svn clone svn://xxxxxxx/${ProjectName}
--authors-file=user.txt --no-metadata ${ProjectName}
git svn clone svn://xxxxxxx/xxxxxx/xxxxx/trunk/xxxxxx
--authors-file=user.txt --no-metadata ProjectName
8.1 建立User更換表
格式:
SVN賬戶名 = Git賬戶名<Git郵箱名>
最后,在Git建立項目倉庫, push代碼到Git倉庫
九栖疑、卸載Jenkins
在終端中執(zhí)行:
'/Library/Application Support/Jenkins/Uninstall.command'
如果老版本命令無效
sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist
sudo rm /Library/LaunchDaemons/org.jenkins-ci.plist
sudo rm -rf /Applications/Jenkins "/Library/Application Support/Jenkins" /Library/Documentation/Jenkins
如果需要刪除已經(jīng)編譯的任務:
sudo rm -rf /Users/Shared/Jenkins
注意
jenkins
是由jar
啟動的讨永,需要java
的最新版本
Mac: 通過系統(tǒng)設置中的java
圖標啟動java
面板,查看java
的版本遇革,
需要升級java
環(huán)境
———————— 2017-08-07 ——————
今天重新安裝Jenkins
時卿闹,在官網(wǎng)下載的Jenkins
2.60,安裝后發(fā)現(xiàn)一直訪問不了默認的http://localhost:8080
萝快,后面發(fā)現(xiàn)Jenkins
2.60需要Java
8環(huán)境锻霎,本地mac還是Java7,但是在jav設置面板升級到8后,貌似制定位置還是7揪漩,一直訪問不了旋恼,后面干脆用Homebrew
安裝Jenkins
和Java
8,然后制定端口8080
brew cask install java
brew install jenkins
java -jar jenkins.war --httpPort=8080
在終端輸入
jenkins restart
就可以啟動jenkins
訪問8080
了奄容。
參考
- 手把手教你利用Jenkins持續(xù)集成iOS項目
- Mac下Jenkins+SVN+Xcode構(gòu)建持續(xù)導出環(huán)境
- mac jenkins iOS持續(xù)集成中的坑
- nomadshenzhen
- Jenkins:”ResourceRules.plist: cannot read resources” error after Xcode 6.1
- --resource-rules has been deprecated in mac os x >= 10.10
- installing-jenkins-os-x-homebrew
- IOS 自動化部署 - 最新Jenkins + git +cocoapods + fir - 簡書
- macos - How to uninstall Jenkins? - Stack Overflow