如果xcode公升級到了最新版本,請執行sudo gem install fastlane
,確保安裝最新版本的fastlane。
fastlane會執行一些xcodebuild命令,有可能因超時而失敗,預設的timeout是10秒,retry times是4次,一般只需要把timeout延長就好了,方法是新增環境變數fastlane_xcodebuild_settings_timeout
,如
export fastlane_xcodebuild_settings_timeout=100
。
使用fastlane最主要的工作在於配置fastfile,它負責定義稱為lane的fastlane任務。fastlane init為我們建立了乙個已經可以使用的fastfile模版。
before_all就是先於所有lane執行的任務,cocoapods預設是開啟的,也就是每次執行fastlane任務都會先執行pod install。一般來說這並不是我們想要的,建議讀者刪除或注釋掉這一行。before_all do
# env["slack_url"] = ""
cocoapods
# carthage
end
test任務通過呼叫scan執行自動化測試。scan是fastlane工具箱中的乙個工具,專門用於執行自動化測試。lane :test do
scan
end
lane :beta do
pilot
# sh "your_script.sh"
# you can also use other beta testing services here (run `fastlane actions`)
end
提測testflight就變成了敲乙個gym(
scheme: "segmentfault",
export_options: })
fastlane beta
命令這麼簡單——其實也沒那麼簡單,itunes connect會要求你登陸,可能還要做two factor auth——下文會聊到如何連這個登陸的步驟都省略。
上面這個lane是fastfile模版裡沒有的,需要我們自己新增。提測enterprise就是敲個lane :enterprise do
gym(scheme: "segmentfault", export_method: "enterprise")
end
fastlane enterprise
命令。
這裡要注意的是,在執行fastlane enterprise
或fastlane beta
之前,要確保專案的code signing配置無誤,enterprise和testflight的配置不一樣,因而在二者間切換時要注意修改配置。
fastfile是個ruby指令碼。
——也就是說你可以把它當成乙個ruby指令碼來寫。你不需要把自己侷限於只做一些「規定動作」,你盡可以在lane中做一些「自選動作」。發郵件啊,或是發slack訊息啊,具體做什麼就隨您方便了。以slack為例。
到此為止我們已經看到了fastlane可以為我們節約多少時間精力。如果把它跟其他工具比如jenkins結合,搭建持續整合服務,還可以節省更多時間精力——還可以更酷。before_all do
env["slack_url"] = "."
enddesc "runs all the tests"
lane :test do
scan(scheme: "segmentfault")
slack
endlane :enterprise do
slack(
message: "segmentfault started enterprise archiving."
)gym(scheme: "segmentfault", export_method: "enterprise")
slack(
message: "segmentfault finished enterprise archiving. uploading...."
)end
本文以介紹fastlane為主,關於持續整合和jenkins請讀者自己去了解。
上文提到提測testflight需要登陸itunes connect,但是在持續整合的「全自動化」環境中,這種需要管理員敲鍵盤的操作是不存在的。
這就需要我們預先維護乙個login session。具體操作如下
執行fastlane spaceauth -u user@email.com
,生成session cookie。
通過環境變數fastlane_session
提供session cookies。
這裡簡述fastlane使用中的常見問題及解決方法——重要之處在於你要通過閱讀log找出問題是什麼。
problem 1
xcodebuild命令執行超時。
上文提到過這個問題。
solution
新增環境變數fastlane_xcodebuild_settings_timeout
,如
export fastlane_xcodebuild_settings_timeout=100
。
problem 2
錯誤的provisioning profile。
比如你要打testflight包,卻提供了enterprise的provisioning profile。
solution
這是乙個常規的code signing問題,通過xcode很容易解決,把錯誤的provisioning profile替換成正確的就好了。有時也可能provisioning profile是正確的,而其他配置與其不匹配,那麼修改其他配置使之匹配就好了。
problem 3
session cookie過期。
solution執行login to itunes connect (user@email.com)
two factor authentication for account 'user@email.com' is enabled
your session cookie has been expired.
fastlane spaceauth -u user@email.com
,生成session cookie。
通過環境變數fastlane_session
提供session cookie。
problem 4
重複/過低的版本號。
error itms-90189: "redundant binary upload. there already exists a binary upload with build '4' for version '2.0.9'"上面這段error log反饋了兩個問題,一是version 2.0.9已經有build 4了,不要重複提交version與build相同的binary;二是2.1.0版本已經提交過了,不要提交比它低的版本。error itms-90186: "invalid pre-release train. the train version '2.0.9' is closed for new build submissions"
solution
修改版本號。
整合與持續整合介紹
簡單來說,就是把開發好的 提交到系統中,就是整合。持續整合就是頻繁的 一天多次 將 整合到主幹。1 快速發現錯誤。每完成一點更新,就整合到主幹,可以快速發現錯誤,定位錯誤也比較容易。2 節省人力成本 3 加快軟體開發進度 4 實時交付 讓產品可以快速迭代,同時還能保持高質量。在整合到主幹之前,先進行...
CICD 持續整合與持續交付
持續整合與持續交付是軟體開發和交付中的實踐。我們專案中一直在踐行持續整合 ci continuous integration 持續交付 cd continuous delivery 未能達到理想狀態,只能實踐一部分。這篇文章用於總結ci cd的實踐。什麼是持續整合?軟體開發中,整合是乙個很可能發生未...
持續整合與灰度發布
持續整合 continuous integration,簡稱ci 是一種軟體開發實踐,即團隊開發成員經常整合它們的工作,通常每個成員每天至少整合一次,也就意味著每天可能會發生多次整合。每次整合都通過自動化的構建 包括編譯,發布,自動化測試 來驗證,從而盡快地發現整合錯誤。許多團隊發現這個過程可以大大...