一、Fastlane環境搭建:http://www.lxweimin.com/p/703534031e42
二、Fastlane自動打包并發布:http://www.lxweimin.com/p/703534031e42
1、cd到項目,初始化fastlane
fastlane init
2、編輯AppFile信息
app_identifier "ineyee.TestApp"
apple_id "2487407179@qq.com"
3、編輯fastlane自動打包和發布腳本,Fastfile文件(沒什么特殊需要的話,下面只需要改一下project_name)
project_name = "CICDTestApp"
output_platform = "蒲公英"
default_platform(:ios)
platform :ios do
# 描述一下Fastlane正在做什么
desc "????????????Fastlane自動打包并發布#{project_name}到#{output_platform}????????????"
# 將來執行fastlane beta命令來開始自動打包并發布,beta可以修改
lane :beta do
# add actions here: https://docs.fastlane.tools/actions
gym(
# 每次打包之前clean一下以前的編譯信息
clean: true,
# 工程的名字,不是App顯示的名字
scheme: "#{project_name}",
# 打包模式:Release、Debug、Profile
configuration: "Release",
# 什么包,包含 app-store, validation, ad-hoc, package, enterprise, development, developer-id and mac-application
export_method: "ad-hoc",
# 輸出ipa的名稱
output_name: "#{project_name}.ipa",
# 輸出ipa的路徑
output_directory: "/Users/yiyi/Desktop/#{project_name}_IPA_#{Time.new.strftime("%Y-%m-%-d-%H-%M")}",
# 是否包含bitcode
include_bitcode: false,
# 是否包含symbols
include_symbols: true,
# 這個設置是為了設置Xcode自動配置證書和配置文件,當然也可以手動配置,可以參考文檔
export_xcargs: "-allowProvisioningUpdates"
)
# mac上的通知彈窗,通知打包完畢
notification(app_icon: "./fastlane/icon.png", title: "manager", subtitle: "Fastlane自動打包成功,已導出ipa", message: "準備發布到#{output_platform}……")
# 配置要上傳到的蒲公英賬號
pgyer(api_key:"d36324232ca7de702af30d5d1e754787", update_description:"1、修復已知Bug;\n2、提升部分性能。")
end
end
4、加入蒲公英插件,Gemfile文件里會加入插件
fastlane add_plugin pgyer
5、執行以下命令開始fastlane自動打包并發布(就算你蒲公英控制臺沒創建過這個項目,這個也會幫你自動創建)
fastlane beta
三、Jenkins環境搭建:http://www.lxweimin.com/p/531c959b8cf8
四、先保證能手動打包,然后再保證能用Fastlane打包,最后再Jenkins驅動Fastlane自動打包并發布(本質其實就是把我們單純使用Fastlane時需要往命令行敲命令的操作,搞成了Jenkins的可視化操作加腳本):http://www.lxweimin.com/p/c61eb3890704(自動構建,無參數配置、腳本精簡)、http://www.lxweimin.com/p/531c959b8cf8(有配置哪幾項參數,但是腳本不太精簡)、http://www.lxweimin.com/p/407b91d702b2(參考了一下怎么把Jenkins的配置參數應用在shell腳本里,然后shell腳本又怎么決定Fastlane腳本執行不同的代碼,Fastlane腳本如何拆分成不同的模式)
1、新建一個任務
2、General -> 參數化構建過程
3、Build Steps
shell腳本
#!/bin/bash
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
echo -e "=========安裝更新pod==========="
pod update
echo -e "=======打包上傳======="
## 這里的Configuration和ExportMethod是上面Jenkins配置的選項參數
## 這里的腳本給fastlane腳本傳參數就是beta后面連續的跟key:value即可
fastlane beta configuration:${Configuration} export_method:${ExportMethod}
當然上面的shell腳本是針對于iOS項目的,如果你想打Flutter項目里的iOS包,那我們得在前面進入到iOS目錄下,也就是加一行cd到ios目錄下(注意路徑要準確,否則會報錯,比如不能直接cd ios)
#!/bin/bash
cd /Users/yiyi/Desktop/AuditoryWorks/FlutterProject/nearhub-flutter/ios
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
echo -e "=========安裝更新pod==========="
pod update
echo -e "=======打包上傳======="
## 這里的Configuration和ExportMethod是上面Jenkins配置的選項參數
## 這里的腳本給fastlane腳本傳參數就是beta后面連續的跟key:value即可
fastlane beta configuration:${Configuration} export_method:${ExportMethod}
為了根據配置打出不同模式的包,我們需要修改下Fastlane的腳本(沒什么特殊需要的話,下面只需要改一下project_name)
project_name = "Runner"
configuration = ""
export_method = “”
default_platform(:ios)
platform :ios do
# 描述一下Fastlane正在做什么
desc "????????????Fastlane自動打包并發布????????????"
# 將來執行fastlane beta命令來開始自動打包并發布,beta可以修改
# do后面固定跟一個|options|代表外界命令傳進來的參數
lane :beta do |options|
# add actions here: https://docs.fastlane.tools/actions
configuration = options[:configuration]
export_method = options[:export_method]
gym(
# 每次打包之前clean一下以前的編譯信息
clean: true,
# 工程的名字,不是App顯示的名字
scheme: "#{project_name}",
# 打包模式:Release、Debug、Profile
configuration: "#{configuration}",
# 什么包,包含 app-store, validation, ad-hoc, package, enterprise, development, developer-id and mac-application
export_method: "#{export_method}",
# 輸出ipa的名稱
output_name: "#{project_name}.ipa",
# 輸出ipa的路徑
output_directory: "/Users/yiyi/Desktop/#{project_name}_IPA_#{Time.new.strftime("%Y-%m-%-d-%H-%M")}",
# 是否包含bitcode
include_bitcode: false,
# 是否包含symbols
include_symbols: true,
# 這個設置是為了設置Xcode自動配置證書和配置文件,當然也可以手動配置,可以參考文檔
export_xcargs: "-allowProvisioningUpdates"
)
# ad-hoc包直接上傳到蒲公英;app-store包暫時自己上傳導出的ipa
if (options[:export_method] == "ad-hoc")
# mac上的通知彈窗,通知打包完畢
notification(app_icon: "./fastlane/icon.png", title: "manager", subtitle: "Fastlane自動打包成功", message: "準備發布到蒲公英……")
# 配置要上傳到的蒲公英賬號
pgyer(api_key:"d36324232ca7de702af30d5d1e754787", update_description:"1、修復已知Bug;\n2、提升部分性能。")
else
# mac上的通知彈窗,通知打包完畢
notification(app_icon: "./fastlane/icon.png", title: "manager", subtitle: "Fastlane自動打包成功,已導出ipa", message: "")
end
end
end
4、ok,接下來就可以發起自動打包了
(1)選中你想要打包的這個項目
(2)然后配置一下你要打什么分支、什么模式的包,開始構建即可
(3)開始構建即可
5、然后去蒲公英掃碼安裝就好了
6、然后關于Jenkins服務,當你啟動后不關掉或者不關電腦的話,它就是一直啟動的,Jenkins的網頁就一直能訪問,如果你想關掉就關掉,用的時候再打開,后面這個-lts看你安裝jenkins的時候是brew install jenkins-lts還是brew install jenkins,后者的話就不需要加這個-lts
啟動 jenkins: brew services start jenkins-lts
停止 jenkins:brew services stop jenkins-lts
重啟 Jenkins:brew services restart jenkins-lts
五、安卓端基本跟上面一樣的操作甚至更少的操作:http://www.lxweimin.com/p/6776d142aa9a,無非就是fastlane腳本文件里稍有區別而已
project_name = "Runner"
configuration = ""
default_platform(:android)
platform :android do
lane:beta do
puts “Debug版本開始打包"
gradle(task:'clean')
gradle(
task: 'assemble',
build_type: 'Debug',
)
puts "Debug版本打包成功”
puts "開始上傳到蒲公英"
pgyer(api_key:"d36324232ca7de702af30d5d1e754787", update_description:"1、修復已知Bug;\n2、提升部分性能。")
puts "上傳到蒲公英成功”
# 在上傳完apk后,打開apk的存放文件夾,起到提示上傳完成的作用
system "open /Users/yiyi/Desktop/apk/debug”
end
lane:beta do
puts “Debug版本開始打包"
gradle(task:'clean')
gradle(
task: 'assemble',
build_type: ‘Release',
)
puts "Debug版本打包成功”
puts "開始上傳到蒲公英"
pgyer(api_key:"d36324232ca7de702af30d5d1e754787", update_description:"1、修復已知Bug;\n2、提升部分性能。")
puts "上傳到蒲公英成功”
# 在上傳完apk后,打開apk的存放文件夾,起到提示上傳完成的作用
system "open /Users/yiyi/Desktop/apk/debug”
end
end
六、一些錯誤及解決辦法: