美文网首页自动化打包
iOS 实践 Jenkins + fastlane

iOS 实践 Jenkins + fastlane

作者: 切一斤桃花卖酒钱 | 来源:发表于2019-03-15 13:55 被阅读0次

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

Why fastlane

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

  • 签名(证书、描述文件)
  • 打包发布(testflight、appstore)
  • 上传符号表到bugly(crashlytics)
  • 推送通知到 slack(蒲公英、fir.im)

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

Why Jenkins

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

  • 论坛活跃,遇到问题容易解决
  • 控制每次代码最新
  • 只需要配置一次 fastlane 环境
  • 一键打包,GUI,人人可以操作,不止程序员
  • 支持进一步集成更多操作

具体安装过程参见 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

  • webhook + github 指定条件(比如 push、release)触发自动构建(Note:自动构建很好用,可以用来每次提交代码的时候自动跑 codereview/unitest 等等)
  • ngrok, 内网穿透,随时随地可以连接公司打包机进行打包

缺点

  • jenkins 经常不稳定,同样的代码几次拉取情况都不同
  • fastlane action 过多,让人眼花缭乱

参考

相关文章

网友评论

    本文标题:iOS 实践 Jenkins + fastlane

    本文链接:https://www.haomeiwen.com/subject/ezllmqtx.html