安装fastlane
github仓库: https://github.com/fastlane/fastlane
fastlane官网: https://docs.fastlane.tools/
fastlane actions: https://docs.fastlane.tools/actions/
一个配置文档: https://www.jianshu.com/p/0a113f754c09
上传到蒲公英: https://www.pgyer.com/doc/view/fastlane
一个自定义lanes组的示例: https://github.com/thierryxing/Fastfiles/tree/master/fastlane/actions
主要支持的操作:
- Testing
- Building: 创建,编译一个项目
- Screenshots: 截图
- Project: 项目配置相关的actions
- Code Signing: 项目签名相关
- Documentation: 导出文档
- Releasing your app: 将app上传到appstore
- Source Control: git控制actions
- Notifications: 通知相关
安装
安装教程请看这里: https://www.jianshu.com/p/0a113f754c09
需要注意的是, 要想让项目build版本自动更新, 必须修改: Build Settings> Versioning>Current Project Version
, 这里必须填一个版本号, 可以随便填一个. 然后Versioning System
可以选择Versioning System
.
导出打包好的文件到指定目录
使用gym打包时候指定output_directory
即可.
desc "打包项目到指定目录"
lane :package do
dir="./fastlane/build/Package"
puts("*************| 打包项目到目录 |*************")
updateProjectBuildNumber #更改项目build号
# 开始打包
gym(
#输出的ipa名称
scheme: "CarOwners",
output_name:"Package_CarOwners_#{get_build_number()}",
silent: false, # 隐藏没有必要的building信息
clean:false, # 是否清空以前的编译信息 true:是
configuration:"Release", # 指定打包方式,Release 或者 Debug
export_method:"development", # 指定打包所使用的输出方式,目前支持app-store, package, ad-hoc, enterprise, development
buildlog_path: "#{dir}/fastlanelog", # fastlane构建ipa的日志输出目录
output_directory:"#{dir}", # 指定输出文件夹
)
puts("\n*************| 打包完成 |*************\n")
puts('output_directory: "#{dir}"')
notification(title: "打包成功!", message: "打包成功,详情请查看控制台!")
end
发布测试版本应用到蒲公英
发布测试版本到蒲公英平台, 详情参照蒲公英平台提供的文档: https://www.pgyer.com/doc/view/fastlane
desc "打包应用并上传到蒲公英平台"
lane :pgy do |options|
updateProjectBuildNumber #更改项目build号
dir="./fastlane/build/Pgy"
# 开始打包
gym(
#输出的ipa名称
scheme: "CarOwners",
output_name:"#{scheme}_#{get_build_number()}",
clean:true, # 是否清空以前的编译信息 true:是
configuration:"Release", # 指定打包方式,Release 或者 Debug
export_method:"development", # 指定打包所使用的输出方式,目前支持app-store, package, ad-hoc, enterprise, development
output_directory:"#{dir}", # 指定输出文件夹
)
pgyer(api_key: "cd1ac371b28c9d53930d780925b0ba73",
user_key: "ffb13d5ca261cf0dab6b8c00f61b4063",
update_description: options[:desc]) #desc表示本次提交的更新描述
notification(title: "发布成功!",
message: "已成功上传到蒲公英平台, 赶快联系测试人员开始测试吧!?",
open: "https://www.pgyer.com/czb365")
end
发布应用到AppStore
发布到appstore就很简单了,打包之后直接使用action upload_to_app_store
, 即可自动上传到appstore并提交审核.
desc "Push a new release build to the App Store"
lane :release do
dir="./fastlane/build/AppStore"
gym(workspace: "CarOwners.xcworkspace",
scheme: "CarOwners",
output_directory:"#{dir}",
buildlog_path: "#{dir}/fastlanelog", # fastlane构建ipa的日志输出目录
)
upload_to_app_store
notification(title: "发布成功!",
message: "已成功发布到appstore, 请查验!",
open: "https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/ra/ng/app/1116025241")
end
一个简单的Demo
# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
# https://docs.fastlane.tools/actions
#
# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane
# 自动追加版本号
def updateProjectBuildNumber
currentTime = Time.new.strftime("%Y%m%d")
build = get_build_number()
if build.include?"#{currentTime}."
# => 为当天版本 计算迭代版本号
lastStr = build[build.length-2..build.length-1]
lastNum = lastStr.to_i
lastNum = lastNum + 1
lastStr = lastNum.to_s
if lastNum < 10
lastStr = lastStr.insert(0,"0")
end
build = "#{currentTime}.#{lastStr}"
else
# => 非当天版本 build 号重置
build = "#{currentTime}.01"
end
puts("*************| 更新build #{build} |*************")
# => 更改项目 build 号
increment_build_number(
build_number: "#{build}"
)
end
default_platform(:ios)
platform :ios do
dir="./fastlane/build/AppStore"
desc "Push a new release build to the App Store"
lane :release do
gym(workspace: "CarOwners.xcworkspace",
scheme: "CarOwners",
output_directory:"#{dir}",
buildlog_path: "#{dir}/fastlanelog", # fastlane构建ipa的日志输出目录
)
upload_to_app_store
notification(title: "发布成功!", message: "已成功发布到appstore, 请查验!", open: "https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/ra/ng/app/1116025241")
end
desc "打包应用并上传到蒲公英平台"
lane :pgy do |options|
updateProjectBuildNumber #更改项目build号
dir="./fastlane/build/Pgy"
# 开始打包
gym(
#输出的ipa名称
scheme: "CarOwners",
output_name:"#{scheme}_#{get_build_number()}",
clean:true, # 是否清空以前的编译信息 true:是
configuration:"Release", # 指定打包方式,Release 或者 Debug
export_method:"development", # 指定打包所使用的输出方式,目前支持app-store, package, ad-hoc, enterprise, development
output_directory:"#{dir}", # 指定输出文件夹
)
pgyer(api_key: "cd1ac371b28c9d53930d780925b0ba73",
user_key: "ffb13d5ca261cf0dab6b8c00f61b4063",
update_description: options[:desc]) #desc表示本次提交的更新描述
notification(title: "发布成功!",
message: "已成功上传到蒲公英平台, 赶快联系测试人员开始测试吧!?",
open: "https://www.pgyer.com/czb365")
end
desc "打包项目到指定目录"
lane :package do
notification(title: "打包", subtitle: "开始打包", message: "正在打包中, 请稍后...")
dir="./fastlane/build/Package"
puts("*************| 打包项目到目录 |*************")
updateProjectBuildNumber #更改项目build号
# 开始打包
gym(
#输出的ipa名称
scheme: "CarOwners",
output_name:"Package_CarOwners_#{get_build_number()}",
silent: false, # 隐藏没有必要的building信息
clean:false, # 是否清空以前的编译信息 true:是
configuration:"Release", # 指定打包方式,Release 或者 Debug
export_method:"development", # 指定打包所使用的输出方式,目前支持app-store, package, ad-hoc, enterprise, development
buildlog_path: "#{dir}/fastlanelog", # fastlane构建ipa的日志输出目录
output_directory:"#{dir}", # 指定输出文件夹
)
puts("\n*************| 打包完成 |*************\n")
puts('output_directory: "#{dir}"')
notification(title: "打包成功!", message: "打包成功,详情请查看控制台!")
end
#执行lane成功后的回调
after_all do |lane|
#发送一个桌面通知
notification(title: "execute success", subtitle: "执行成功!", message: "lane已经执行成功了")
end
# 如果流程发生异常会走这里并终止
error do |lane, exception|
puts("#{exception.message}")
notification(title: "执行#{lane}发生异常!", message: "发生异常, 详情请查看控制台!")
end
end
详细用法请参考官放文档
fastlane官网: https://docs.fastlane.tools/
其它
安装使用Jenkins教程: https://www.jianshu.com/p/41ecb06ae95f