自动化打包

iOS 实践 Jenkins + fastlane

2019-03-15  本文已影响0人  切一斤桃花卖酒钱

以下内容并非着眼于工具的使用,而是分享使用的原因、优缺点以及实践中遇到的问题。

Why fastlane

首先 fastlane 实现持续部署CD(Continuous Delivery)。 fastlane 主要负责以下:

省时省事,高效便捷,配置简单,具体安装过程参见 fastlane doc

Why Jenkins

fastlane 轻松的解决了打包流程中繁琐重复的部分,但是就和 cocoapods 一样,每台设备都要配置相应的环境以及代码拉取等操作,有没有可能只配置一次,而所有人都可以使用的,很容易的想到了打包机。使用 Jenkins 每次打包自动拉取最新代码,同时运行 fastlane 命令实现持续集成CI(Continuous Integration)的目的。Jenkins 优点:

具体安装过程参见 Jenkins doc

How fastlane

使用过程注意点总结如下:

  1. 推荐使用 RubyGems 安装
  2. fastlane 主要包含 FastfileAppfile两个主要文件,Appfile主要是账号的信息,如果你有多个开发者账号,那么此处要指明当前工程的 team_iditc_team_id,而 Fastfile 主要是需要做的操作,以 lane 来指定,自带了很多的 action 和 plugins。

How Jenkins

  1. 强烈建议通过 jenkins.war运行,如果通过 .dmg 包安装,jenkins 会自动创建一个用户,并且在 Daemon 中运行,这样会带来很多证书以及权限的问题。
  2. 配置中设置 Jenkins URL 可以局域网内其他地址访问本打包机。
  3. 关于 CI 中的苹果账号二次验证问题(2 Step Verification) spaceship

Example 🌰

分享一个典型例子: 工程包含 submodule、多个仓库(Repository),项目包含 shareExtension 涉及到多个证书签名的问题。这些都是在过程中遇到了不少坑。

Fastfile

default_platform(:ios)

platform :ios do
  desc "Push a new release build to the App Store"

  lane :release do
      get_certificates           
      get_provisioning_profile(app_identifier: "com.xxx.xxx")
      get_provisioning_profile(app_identifier: "com.xxx.xxx.shareextension")

    scheme_name = "xxx"
    configuration = 'Release'
    output_directory = File.expand_path("..", Dir.pwd) + File::Separator + 'build'
    
    setup_jenkins(keychain_password: "xxx")
    gym(
      clean: true,
      scheme: scheme_name,
      export_method: "app-store",
      configuration: configuration,
      output_directory: output_directory
       )
    upload_to_testflight(skip_waiting_for_build_processing: true)
    uploadBuglydsYM
  end

  lane :uploadBuglydsYM do # BuglydSYMUploader已做相应修改
    puts("------开始bugly符号表上传------")

    Dir.chdir("../BuglydSYMUploader")
    # puts Dir.pwd
    version = get_version_number(target: "xxx")
    # puts version
    sh("sh dSYMUpload.sh xxx xxx com.xxx.xxx #{version} ../build ../build 1")

    puts("-----结束bugly符号表上传------")
  end

end

Addition

缺点

参考

上一篇 下一篇

猜你喜欢

热点阅读