1.初始化fastlane
fastlane init
2.在终端中,输入以下命令,即可安装蒲公英的 fastlane 插件。
fastlane add_plugin pgyer
3.修改fastlane文件夹里面的Fastlane
###将********对应替换成自己项目对应的
#测试包命令 (版本描述)
# fastlane develop desc:测试自动发包3.6.0B1
# 网络请求依赖
require 'net/http'
require 'uri'
require 'json'
#蒲公英api_key和user_key
pgyer_api_key = "*****************"
pgyer_user_key = "*****************"
#下载地址
app_url = "*****************"
app_icon = "*****************"
#钉钉
DingTalkUrl = "*****************"
default_platform(:ios)
platform :ios do
desc "Push a new release build to the App Store"
lane :release do
build_app(workspace: "*****************.xcworkspace", scheme: "*****************")
upload_to_app_store
end
desc "测试包"
lane :develop do |options|
gym(
#输出的ipa名称
output_name:”*****************”,
# 是否清空以前的编译信息 true:是
clean:true,
# 指定打包方式,Release 或者 Debug
configuration:"Debug",
# 指定打包所使用的输出方式,目前支持app-store, package, ad-hoc, enterprise, development
export_method:"development",
# 指定输出文件夹
output_directory:"./fastlane/development",
)
puts "开始上传蒲公英"
pgyer(api_key: “#{pgyer_api_key}”,
user_key: “#{pgyer_user_key}”,
password: "", install_type: "2",
update_description: options[:desc]
)
puts '开始钉钉'
app_patch = "./fastlane/development/*****************.ipa"
app_version = get_ipa_info_plist_value(ipa: app_patch, key: "CFBundleShortVersionString")
app_build_version = get_ipa_info_plist_value(ipa: app_patch, key: "CFBundleVersion")
app_name = get_ipa_info_plist_value(ipa: app_patch, key: "CFBundleDisplayName")
dingTalk_url = DingTalkUrl
markdown =
{
msgtype: "link",
link: {
text: {
各位小姐姐、小哥哥 最新版本已发布,辛苦测试",
title: "iOS #{app_name} #{app_version} (#{app_build_version}) 内测版",
picUrl: "#{app_icon}",
messageUrl: "#{app_url}"
}
}
uri = URI.parse(dingTalk_url)
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request.add_field('Content-Type', 'application/json')
request.body = markdown.to_json
response = https.request(request)
puts "------------------------------"
puts "Response #{response.code} #{response.message}: #{response.body}"
end
end
ReactNative项目 自动化打包
Jenkins
Fastlane
default_platform(:ios)
# 网络请求依赖
require 'net/http'
require 'uri'
require 'json'
platform :ios do
desc "Description of what the lane does"
workspace = "_RN.xcworkspace"
scheme = "_RN"
bundleid = ""
currentTime = Time.new.strftime("%Y-%m-%d %H-%M-%S")
ipa_name = "AnItemForACar_RN"
output_path = "../ios/fastlane/#{ipa_name} #{currentTime}"
ipa_path = "#{output_path}/#{ipa_name}.ipa"
build_number=""
# 蒲公英 api_key user_key
pgyer_api_key = ""
payer_user_key = ""
#钉钉
app_url=''
app_icon=''
dingTalk_url=''
# firim api_token
# firim_api_token = "xxxxxxxx"
# bugly app_id app_key
bugly_app_id = ""
bugly_app_key = ""
# crashlytics api_token build_secret
# crashlytics_api_token = "xxxxxxx"
# crashlytics_build_secret = "xxxxxxxx"
before_all do |lane, options|
#fastlane beta key1:value key2:value2
#value = options[:key1]
#value2 = options[:key2]
# 切到 develop 分支
sh 'git checkout uat'
# 代码
git_pull
# build 号加1
increment_build_number_in_plist(
target: "#{scheme}"
)
#increment_version_number_in_plist(
# target: 'TestDemo',
# version_number: '1.0'
#)
# 下面是拿到新的版本号,提交代码
build_number = get_build_number_from_plist(target: "#{scheme}")
#git_commit(path:".", message:"Bump build to #{build_number}")
#sh 'git push origin develop'
# pod install
cocoapods(repo_update: false)
puts "build_number#{build_number}"
end
lane :test do |options|
end
lane :dev do |options|
gym(
scheme: "#{scheme}",
export_method: "development",
clean:true,
workspace: "#{workspace}",
output_directory: "#{output_path}",
output_name: "#{ipa_name}",
configuration: "Release",
)
puts "正在上传蒲公英#{build_number}"
pgyer(api_key: "#{pgyer_api_key}",
user_key: "#{payer_user_key}",
password:"",
install_type:"2",
update_description:"测试版本B #{build_number}"
)
puts "上传蒲公英Success!!!!!!"
puts "正在发送钉钉通知"
# 钉钉机器人
#ipa_path = '/Users/dataenligten/.jenkins/workspace/AnItemForACar_RN_iOS/ios/fastlane/AnItemForACar_RN 2020-03-07 19-23-01/AnItemForACar_RN.ipa'
app_version = get_ipa_info_plist_value(ipa: ipa_path, key: "CFBundleShortVersionString")
app_build_version = get_ipa_info_plist_value(ipa: ipa_path, key: "CFBundleVersion")
app_name = get_ipa_info_plist_value(ipa: ipa_path, key: "CFBundleDisplayName")
markdown = {
"msgtype": "link",
"link": {
text: "iOS #{app_name} 更新了!!!",
title: "iOS #{app_name} #{app_version} (B#{app_build_version}) 新版本",
picUrl: "#{app_icon}",
messageUrl: "#{app_url}"
},
"at": {
isAtAll: true
}
}
uri = URI.parse(dingTalk_url)
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request.add_field('Content-Type', 'application/json')
request.body = markdown.to_json
response = https.request(request)
puts "------------------------------"
puts "Response #{response.code} #{response.message}: #{response.body}"
puts "发送钉钉通知Success!!!!!!"
#firim(firim_api_token: "#{firim_api_token}")
# 上传dSYM到Bugly
#upload_app_to_bugly(
# file_path: "#{ipa_path}",
# app_key: "#{bugly_app_key}",
# app_id: "#{bugly_app_id}",
# pid: "2", #应用平台标识, 用于区分产品平台 android:1 iOS:2
# download_limit: 999
#)
#上传dSYM到crashlytics
#crashlytics(
# api_token: "069c7f2852fe97ae2b9572f799200a2ae1da3621",
# build_secret: "0cb5ed2e8ff4ed31a5b03093e96fcbc3b81ade7021295e2a2e0afe35661c5d3b"
#)
end
lane :adhoc do |options|
build_ios_app(
clean: true,
workspace: "#{workspace}",
output_directory: "#{output_path}",
output_name: "#{ipa_name}",
scheme: "#{scheme}",
configuration: "Debug",
export_method: "ad-hoc",
export_options: {
provisioningProfiles: {
"#{bundleid}" => "Provisioning Profile Name",
}
},
export_xcargs: "-allowProvisioningUpdates"
)
pgyer(api_key: "#{pgyer_api_key}", user_key: "#{payer_user_key}")
firim(firim_api_token: "#{firim_api_token}")
# 上传dSYM到Bugly
upload_app_to_bugl(
file_path: "#{ipa_path}",
app_key: "#{bugly_app_key}",
app_id: "#{bugly_app_id}",
pid: "2", #应用平台标识, 用于区分产品平台 android:1 iOS:2
download_limit: 999
)
#上传dSYM到crashlytics
crashlytics(
api_token: "#{crashlytics_api_token}",
build_secret: "#{crashlytics_build_secret}"
)
end
lane :app_store do |options|
desc "Push a new release build to the App Store"
increment_build_number(xcodeproj: "AnItemForACar_RN.xcodeproj")
#build_app(workspace: "AnItemForACar_RN.xcworkspace", scheme: "AnItemForACar_RN")
#upload_to_app_store
build_ios_app(
clean: true,
workspace: "#{workspace}",
output_directory: "#{output_path}",
output_name: "#{ipa_name}",
scheme: "#{scheme}",
export_method: "app-store",
export_options: {
provisioningProfiles: {
"#{bundleid}" => "Provisioning Profile Name",
}
},
export_xcargs: "-allowProvisioningUpdates"
)
# 上传dSYM到Bugly
upload_app_to_bugl(
file_path: "#{ipa_path}",
app_key: "#{bugly_app_key}",
app_id: "#{bugly_app_id}",
pid: "2", #应用平台标识, 用于区分产品平台 android:1 iOS:2
download_limit: 999
)
#上传dSYM到crashlytics
crashlytics(
api_token: "#{crashlytics_api_token}",
build_secret: "#{crashlytics_build_secret}"
)
#可以上传屏幕截图、元数据、二进制文件到App sotre Connect
deliver(
submit_for_review: true,
automatic_release: false,
force: true,
skip_metadata: true,
skip_screenshots: true,
)
end
end