iOS Jenkins fastlane Bugly自動打包上傳firm appstore

總體步驟

  • 1.安裝整體環(huán)境(cocoapods、fastlane、jenkins)

  • 2.配置jenkins

  • 3.配置證書

  • 4.編寫fastfile

安裝cocoapos 和fastlane

1.安裝cocoapods
2.安裝fastlane
3.在項目文件執(zhí)行fastlane安裝 然后一步一步選擇
4 .安裝bugly上傳DYSM action
fastlane add_plugin upload_dsym_to_bugly
5.安裝firm上傳action
fastlane add_plugin fir_cli

cd [your_project_folder]

fastlane init

fastlane deliver init (firm 插件 https://github.com/FIRHQ/fastlane-plugin-fir_cli)

上傳App Store時有二次驗證會導致上傳失敗這時候需要執(zhí)行以下步驟
1.  在appleid.apple.com/account/manage上生成一個application specific password。
2.配置環(huán)境變量  vim ~/.bash_profile 
export FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD=YOUR_PSD
3.執(zhí)行 fastlane spaceauth -u abcd@qq.com 按提示獲取session信息。
復制session信息(很長一大段) 配置環(huán)境變量vim ~/.bash_profile 
export FASTLANE_SESSION='YOUR SESSION'

Fastlane

查看版本

java -version

需要安裝至少java1.8也不能太高

Error: Cask 'java8' is unavailable: No Cask with this name exists.

解決

$ brew tap caskroom/versions

不是需要的版本就安裝需要的版本,一般錯誤下面都有命令
還有可能安裝了java1.8但是本地有幾個版本,刪掉其它的或者改變.bashProfile配置就可以了
java文件/Library/Java/JavaVirtualMachines

安裝jenkins穩(wěn)定版

$ brew install jenkins-lts
$ java -jar /usr/local/Cellar/jenkins/2.49/libexec/jenkins.war --httpPort=8080

2.49是jenkins版本號,8080是未被占用的端口號(占用可以用其它的比如9090)
$ jenkins -v 查看版本

執(zhí)行

 $ jenkins-lts

有時候會突然莫名奇妙的被拒絕訪問,重新執(zhí)行映射端口號命名就可以了
然后瀏覽器打開http://localhost:8080就會出現配置jenkins(最好不用safari打開)

http://localhost:8080/exit //退出Jenkins
http://localhost:8080/restart //重啟
http://localhost:8080/reload //重新加載

jenkins配置

前面都是按照步驟走,等插件下載好設置好用戶名密碼就可以

1.設置管理員權限

Manage Jenkins -> Configure Global Security -> 選中安全矩陣 -> 點擊 add user or group按鈕 -> 輸入自己用戶名 -> 勾選Administer -> 保存

2.安裝插件
1、Xcode integration

2、GIT plugin

3、GitLab Plugin

4、Gitlab Hook Plugin

5、Keychains and Provisioning Profiles Management

6、Git Parameter(選擇Git版本和分支)

3.配置Keychains and Provisioning Profiles Management
1.獲取login.keychain(位置:/Users/用戶名/Library/Keychains,login.keychain-db拷貝改名為login.keychain)
2.上傳login.keychain
截屏2021-01-13 下午5.45.39.png

截屏2021-01-13 下午5.46.43.png
添加code signing identity(就是開發(fā)和發(fā)布證書的常用名稱)
截屏2021-01-13 下午5.54.29.png
截屏2021-01-13 下午5.50.47.png
4.新建項目(可以根據自己需要選擇)
截屏2021-01-13 下午5.59.48.png
5.配置項目
截屏2021-01-13 下午6.04.11.png
截屏2021-01-13 下午6.04.24.png
上面這些環(huán)境是在項目中定義的
Test             測試
PreRelease       預發(fā)布
Release          發(fā)布
Debug            開發(fā)
截屏2021-01-13 下午6.04.42.png
截屏2021-01-13 下午6.05.00.png
截屏2021-01-13 下午6.05.11.png
截屏2021-01-13 下午6.14.26.png
#!/bin/bash -l 
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

cd xny-app-ios 

pod install --verbose --no-repo-update 

changelog="${mbranch}-${export_method}-${configuration}"

if [ ${export_method} == "app-store" ];
then
    echo "***********====== appstore =====***************"
    fastlane upToAppStore
else
    echo "***********====== other =====***************"
    fastlane upfirm configuration:$configuration export_method:$export_method changelog:$changelog
fi    

6.管理證書fastlane match

https://docs.fastlane.tools/actions/match/#match
總體來說就是需要在自己的gitlab上面創(chuàng)建一個存儲證書和描述文件的倉庫,cd到項目中中執(zhí)行 fastlane match init接著輸入倉庫地址,fastlane會在項目的fastlane文件夾下創(chuàng)建Matchfile文件
配置如下

#倉庫地址
git_url("")

storage_mode("git")

type("development") # The default type, can be: appstore, adhoc, enterprise or development

 app_identifier([""])
 username("") # Your Apple Developer Portal username

# For all available options run `fastlane match --help`
# Remove the # in the beginning of the line to enable the other options

# The docs are available on https://docs.fastlane.tools/actions/match

然后執(zhí)行 
fastlane match development
fastlane match adhoc
fastlane match appstore
match 會分別配置不同環(huán)境的證書和描述文件并上傳到我們指定的倉庫
在其它電腦上只需要 執(zhí)行fastlane match development --readonly 就可以配置相應環(huán)境的證書和描述文件,不需要新建證書和描述文件,但是xcode就不要使用automatically manage signing 使用手動配置,選擇相應的描述文件就可以了
在實際配置中發(fā)現有個問題:需要清空電腦的鑰匙串中安裝的證書和~/資源庫/MobileDevice/Provisioning Profiles下的描述文件然后再執(zhí)行fastlane match development --readonly
fastfile文件
#使用方法 cd到項目.xcworkspace目錄 終端輸入 fastlane automaticPackagingUpload

# 定義fastlane版本號
fastlane_version "2.171.0"

# 定義打包平臺
default_platform :ios

#指定項目的scheme名稱
scheme = ""
bundle_id = ""
#firm api_key和user_key
firm_token  = ""

#bugly
buglyAppkey = ""
buglyAppId = ""

#打包輸出路徑
output_directory = "/Users/{customerName}/Desktop/fastlaneBuild/xny/"

output_name = "#{scheme}_#{get_build_number()}"
#apple賬號id
username = ""
#apple開發(fā)組名(如Xiaomianju Network Technology(Shanghai) Co., Ltd.)
team_name = ""


def updateProjectBuildNumber

build = Time.new.strftime("%Y%m%d.%H%M")
# => 更改項目 build 號
increment_build_number(
build_number: "#{build}"
)
end


#"上傳Firm"
platform :ios do

lane :upfirm do|options|

branch = options[:branch]
configuration = options[:configuration]
puts “*************| configuration:#{configuration} |*************”
export_method = options[:export_method]
puts “*************| export_method:#{export_method} |*************”

changelog = options[:changelog]

#cocoapods

updateProjectBuildNumber #更改項目build號

match(type: "development",force_for_new_devices:true,readonly:true)

gym(
#輸出的ipa名稱
output_name:"#{output_name}",
#指定項目的scheme
scheme:"#{scheme}",
# 是否清空以前的編譯信息 true:是
clean:true,
# 指定打包方式,Release 或者 Debug
configuration:configuration,
# 指定打包所使用的輸出方式,目前支持app-store, package, ad-hoc, enterprise, development
export_method: "#{export_method}",
# 指定輸出文件夾
output_directory:"#{output_directory}#{configuration}",
)

puts “*************| 開始上傳firm |*************”

fir_cli api_token:firm_token,changelog:changelog

puts “*************| 上傳firm成功 |*************”

end

#"上傳APPStore"

lane :upToAppStore do|options|

branch = options[:branch]

#cocoapods

updateProjectBuildNumber #更改項目build號

match(type: "appstore",readonly:true)

gym(
#輸出的ipa名稱
output_name:"#{output_name}",
#指定項目的scheme
scheme:"#{scheme}",
# 是否清空以前的編譯信息 true:是
clean:true,
# 指定打包方式,Release 或者 Debug
configuration:"Release",
# 指定打包所使用的輸出方式,目前支持app-store, package, ad-hoc, enterprise, development
export_method:"app-store",
# 指定輸出文件夾
output_directory:"#{output_directory}appstore",
)

puts “*************| 上傳DYSM到Bugly |*************”

output_dysm_name = "#{output_name}.app.dSYM.zip"

upload_dsym_to_bugly(
      file_path: "#{output_directory}appstore/#{output_dysm_name}",
      file_name: "#{output_dysm_name}",
      app_key: "#{buglyAppkey}",
      app_id: "#{buglyAppId}",
      api_version: 1,
      symbol_type: 2, # iOS => 2, Android => 1
      bundle_id: "#{bundle_id}",
      product_version: get_version_number
    )
puts “*************| 上傳DYSM到Bugly成功 |*************”

puts “*************| 開始上傳APPStore |*************”
deliver(
    username:"#{username}",
    team_name:"#{team_name}",
    skip_metadata: true,
    skip_screenshots: true,
    force: true,
)

puts “*************| 上傳APPStore成功 |*************”

end

end

參考資料

pipleLine
http://mmorejon.github.io/en/blog/build-pipeline-jenkins2-as-code-with-ios10-xcode8/
中文文檔

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內容