【iOS/fastlane】自动发布ios_ipa

背景

  • mac 笔记本

安装 fastlane

  • 安装fastlane brew install fastlane
  • 切记及时更新 brew upgrade fastlane,否则可能会出现无法使用的情况
  • 终端切换到ios工程目录中 fastlane init,项目中会生成fastlane文件夹
  • 配置文件夹中的各个文件 Appfile Fastfile Pluginfile report.xml

Appfile

#app_identifier("com.alex.luan") # The bundle identifier of your app
#apple_id("apple@alex.org") # Your Apple email address

#itc_team_id("----") # App Store Connect Team ID
#team_id("---") # Developer Portal Team ID

# For more information about the Appfile, see:
#     https://docs.fastlane.tools/advanced/#appfile

app_identifier "com.alex.luan"
apple_id "apple@alex.org"
itc_team_id "---"
# 这个参数在工程中可以找到
team_id "----"

for_platform :ios do
    team_id '----'
    for_lane :enterprise_lane do
        app_identifier 'com.alex.luan'
        apple_id 'apple@alex.org'
    end
end

Pluginfile

# Autogenerated by fastlane
#
# Ensure this file is checked in to source control!

gem 'fastlane-plugin-versioning'
gem 'fastlane-plugin-firim'
gem 'fastlane-plugin-firim'

Fastfile

fastlane_version "2.46.1"

default_platform(:ios)

platform :ios do

  before_all do

    ENV["FASTLANE_XCODEBUILD_SETTINGS_TIMEOUT"] = "120"
    ENV["FASTLANE_XCODEBUILD_SETTINGS_RETRIES"] = "10"

    ENV["FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD"] = "utxu-qjuy-naod-cjzb"
    ENV["FASTLANE_SESSION"] = '---\n- !ruby/object:HTTP::Cookie\n  name: DES5dfb75937bfd0785ae220bd99a538a2d3\n  value: HSARMTKNSRVXWFlaDFXOojeRi4mcyoDMT7RqoN+1mMyhff6DMF3shWx5R7fnBbBXQ3hjWyhW5gb/UOPhvY1TuJ3blI/c5yfuJF6Lw6ATJyrhjC0KX1HCaJmCwYwZcRsVISdlHsg=SRVX\n  domain: idmsa.apple.com\n  for_domain: true\n  path: "/"\n  secure: true\n  httponly: true\n  expires: \n  max_age: 2592000\n  created_at: &1 2020-07-02 13:31:13.758967000 +08:00\n  accessed_at: *1\n- !ruby/object:HTTP::Cookie\n  name: myacinfo\n  value: DAWTKNV255b0fa2057b29c130c58a5ebe33ad360312d10e68281dcc91c7422c47d003008c81182a6c34624a90a1697e9e5c5871730e173a9c77d78cfe2aa9f095a5d3b0d109b231b116158195469a8c5f607dc5728e059778e38d4d2d4b0f9b8fe2f4661d5654a761e50737f6e194c36fc720025e16d25910e3fbc11e70524cbc957a5eb15043dff18a3a11783673b9eb82964fc84cd793f96f083e06692380cebfef11c9efc1d13faffc7b4b35bf8c2b4b51d5b4c2a63ed2b904c6e11a46e430693042f13d2352c1173eed15bc062607d0d5513e1068f69468472ffec5b20119c08f38f946e3c97900f6401aeb2fbc672e10a667e53b003ef477913328dcac82a4c7fa2f75f58ac155083b0e611831436a6da7943024f01634513e1a7d1dcc87163ae7cb9ba3fddc3e0b548f88ab2cbd50893731237055ffdbe522de490e42ea8490dc4b4704ed771ded345ab646f8ddd4b0407169a526cc41012fcb6fc6f6df9da06c3e62eec2fd061089faed17023cd1f5eb7c0eafe5907a06f69b9c869af62405a174534da267a2b44b5e615f4f97f37a902469979036b8d5386de632b57391446cd4de4adcb67156b87b7bf308865624b231ebd18d3fa7d3cc35b3c3c7110ccaec49c341a7968d3873f832b019183c86712973bf712fee80c10ff901984abeafdc97e34a93843dc43b9acbcf5251e1064d78cecbcb0cedbbe58457af903e2424668e24c438274740ca3c810814afd58f26361346334376364643037643636376637333238326131313239666635363930356263313435306230MVRYV2\n  domain: apple.com\n  for_domain: true\n  path: "/"\n  secure: true\n  httponly: true\n  expires: \n  max_age: \n  created_at: 2020-07-02 13:31:13.759140000 +08:00\n  accessed_at: 2020-07-02 13:31:13.766133000 +08:00\n- !ruby/object:HTTP::Cookie\n  name: dqsid\n  value: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1OTM2Njc4NzQsImp0aSI6IlAyVTA4OEY0cGl4QjlrOU1XamFkRUEifQ.jPri0PXSYXWLsBHMXwqUUp2yux-KtO8pMX1609EyUIU\n  domain: appstoreconnect.apple.com\n  for_domain: false\n  path: "/"\n  secure: true\n  httponly: true\n  expires: \n  max_age: 1800\n  created_at: &2 2020-07-02 13:31:15.819130000 +08:00\n  accessed_at: *2\n'
  end

 def updateProjectBuildNumber
	currentTime = Time.new.strftime("%Y%m%d%H%M%S")
	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}"
	end
	puts("*************| 更新build #{build} |*************")
	# => 更改项目 build 号
	increment_build_number(
	build_number: "#{build}"
	)
  end

   #指定项目的scheme名称
   scheme="scheme"

   # 任务脚本
   platform :ios do

     update_app_identifier(
          app_identifier: "com.alex.luan",
          plist_path: "iosproject/Info.plist",
     )
   
   ENV["EXPORTOPTIONSPLIST"] = "/Users/xxxxx/.jenkins/workspace/WillJob/ExportOptions.plist"

  def sendEmail(title, content)
    puts("will send email title: #{title} content: #{content}")
    system "python ../sendemail.py '#{title}' '#{content}'"
  end

lane :test do |options|
  puts options
  updateProjectBuildNumber
  sendEmail "ios [#{scheme}_#{get_build_number()}] 发包成功", "#{get_build_number()}"end

lane :development_build do |options|
   branch = options[:branch]
   puts "开始打development ipa"
   updateProjectBuildNumber #更改项目build号
   # 开始打包
   gym(
    scheme:"*****",
	  output_name:"#{scheme}_#{get_build_number()}", #输出的ipa名称
	  clean:true, # 是否清空以前的编译信息 true:是
	  configuration:"Release", # 指定打包方式,Release 或者 Debug
	  export_method:"enterprise", # 指定打包所使用的输出方式,目前支持app-store, package, ad-hoc, enterprise, development
    export_xcargs: "-allowProvisioningUpdates",
 	  export_options: { iCloudContainerEnvironment: "Production"},
	  output_directory:"./fastlane/build", # 指定输出文件夹
   )

   # 开始上传FIR
  firim(firim_api_token: "******")

  sendEmail "ios [#{scheme}_#{get_build_number()}] 发包成功", "#{get_build_number()}"end
end

lane :uploadfir do |options|
   firim(firim_api_token: "*****")
end

lane :development_buildtf do|options|
   puts "开始打development_buildtf"
    gym(
      scheme:"****",
      output_name:"#{scheme}_#{get_build_number()}",
      clean: true,
      configuration: "Release",
      export_method:"enterprise",
      output_directory:"./fastlane/build",
      export_options: { iCloudContainerEnvironment: "Production"},
    )
    #上传至testFlight
    upload_to_testflight(
      skip_waiting_for_build_processing: true  #是否跳过等待apple处理的过程
    )
end

end
end

您的一举一动都是对我的莫大支持

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值