Jenkins+Fastlane+自动化打包发布+蒲公英二维码展示 您所在的位置:网站首页 最新丝瓜ios安装二维码 Jenkins+Fastlane+自动化打包发布+蒲公英二维码展示

Jenkins+Fastlane+自动化打包发布+蒲公英二维码展示

2023-04-22 22:21| 来源: 网络整理| 查看: 265

前言:

身为一名iOS开发人员,面临必不可少的一个阶段就是打包测试。虽然xcode可有实现打包,但在测试阶段面临测试人员不断的向你催促需要新的包进行测试就会很让人头疼,打包又是一个重复性极高又很费时间的事情。所以研究了一下jenkins和fastlane的自动打包流程,希望对大家有所帮助,途中也遇到了众多的问题和坑。

如需帮助可直接 联系我

前期准备

Ruby:

fastlane的安装需要Ruby2.0版本以上,虽然mac自带ruby,但是版本可能较低,并且权限较少,所以推荐使用RVM管理ruby版本。

按照这篇文章安装既可以了 Mac安装Ruby版本管理器RVM

xcode命令行工具

xcode-select --install 复制代码

如果已经安装会提示

如果没有安装会出现 xcode-select --install

​ 直接点击安装就可以了,安装完成后再次执行 xcode-select --install 之后出现已经安装的提示了。

Java JDK (这个是Jenkins安装用的,如果不需要jenkins可直接忽略)

可先查看 当前安装的java版本

java -version 复制代码

如果未安装请先前往 JDK下载链接 下载

因为jenkins是用java语言编写的,所以需要java的支持,建议使用1.8版本的JDK

需要先接受协议之后才可以下载

下载完成之后直接安装就可以了,这里就不再赘述。

前期准备工作到这里就完成了

Fastlane

img/fastlane_text.png

fastlane是为iOS和Android应用程序自动化beta部署和发布最简单的方法。🚀可以处理各种繁琐任务,例如生成屏幕截图,处理代码签名和发布应用该程序等.fastlane整合了一系列移动端开发中签名,编译,发布等工具,堪称打包神器。

fastlane初始化 安装fastlane的三种方式

Homebrew

brew cask install fastlane 复制代码

安装程序脚本

下载zip文件。后双击shell脚本即可

RubyGems

gem install fastlane -NV 复制代码 蒲公英插件

这里我们在最后使用了 Jenkins上传蒲公英,为了获取下载二维码。

本文也提到了使用Fastlane上传蒲公英的介绍

Fastlane 安装成功之后 执行安装蒲公英的插件

fastlane add_plugin pgyer 复制代码

如果没什么意外就直接成功了

刚开始我使用的本机自带的ruby, 失败了。然后使用了rvm管理的ruby之后就成功了。

如果遇到了其他问题请大家google一下吧,或者联系我我们一起探讨。

初始化 cd /到自己的项目目录中 复制代码

初始化fastlane

fastlane init 复制代码

如果之前的都没有问题 会出现以下选项

![](https://p1-jj.byteimg.com/tos-cn-i-t2oaga2asx/gold-user-assets/2019/9/6/16d04e00a64a304d~tplv-t2oaga2asx-image.image) 复制代码 Automate screenshots: 自动截屏 Automate beta distribution to TestFlight: 自动发布beta版本到testFlight Automate App Store distribution: 自动发布到App Store Manual setup: 手动设置

这里我们选的是第3个,然后会出现一些选项

1. 📸 Automate screenshots 2. 👩‍✈️ Automate beta distribution to TestFlight 3. 🚀 Automate App Store distribution 4. 🛠 Manual setup - manually setup your project to automate your tasks ? 3 [10:37:53]: ---------------------------------------------------------- [10:37:53]: --- Setting up fastlane for iOS App Store distribution --- [10:37:53]: ---------------------------------------------------------- [10:37:53]: Parsing your local Xcode project to find the available schemes and the app identifier [10:37:53]: $ xcodebuild -showBuildSettings -workspace FastlaneDev.xcworkspace -scheme FastlaneDev [10:37:55]: $ cd `你项目的路径` && agvtool what-version -terse [10:37:55]: -------------------------------- [10:37:55]: --- Login with your Apple ID --- [10:37:55]: -------------------------------- [10:37:55]: To use App Store Connect and Apple Developer Portal features as part of fastlane, [10:37:55]: we will ask you for your Apple ID username and password [10:37:55]: This is necessary for certain fastlane features, for example: [10:37:55]: [10:37:55]: - Create and manage your provisioning profiles on the Developer Portal [10:37:55]: - Upload and manage TestFlight and App Store builds on App Store Connect [10:37:55]: - Manage your App Store Connect app metadata and screenshots [10:37:55]: [10:37:55]: Your Apple ID credentials will only be stored in your Keychain, on your local machine [10:37:55]: For more information, check out [10:37:55]: https://github.com/fastlane/fastlane/tree/master/credentials_manager [10:37:55]: [10:37:55]: Please enter your Apple ID developer credentials [10:37:55]: Apple ID Username: `你的Apple ID` [10:38:16]: Logging in... 复制代码 ![](https://p1-jj.byteimg.com/tos-cn-i-t2oaga2asx/gold-user-assets/2019/9/6/16d04e0a8d184c86~tplv-t2oaga2asx-image.image) 复制代码

如果你账号下有多个team会让你选择一下

然后等待安装

在这期间我遇到了bundle update这句话一直不动,我重新init了一遍就好了

成功之后 打开我们的项目目录发现多了这个文件

恭喜你 初始化成功了 !!!

配置Fastlane 文件名描述Appfile从 Apple Developer Portal 获取和项目相关的信息 详情Fastfile核心文件,存放lane任务Deliverfiledeliver的配置文件,从 iTunes Connect 获取和项目相关的信息详细metadata同步iTC中的元数据screenshots同步iTC中的截图

这里给打家推荐一篇配置的文章Fastfile参考配置

下面是我的配置仅供参考,没有用fastlane上传蒲公英,因为想要在jenkins里面获取二维码暂时的解决办法使用jenkins上传蒲公英 如果需要fastlane上传直接打开的注释进行了

# 导出路径 $ipa_output_directory = "/Users/xx/xx/fastlaneBuild" # 上传蒲公英的包 路径 $ipa_output_upload_directory = "/Users/xx/.jenkins/workspace/xx/ipa" # jenkins匹配的包名 $jenkins_name = "项目名" default_platform(:ios) # 应用名词 scheme_name = "项目名字" # 获取version version = get_info_plist_value(path: "./#{scheme_name}/Info.plist", key: "CFBundleShortVersionString") # 获取build版本号 build = get_info_plist_value(path: "./#{scheme_name}/Info.plist", key: "CFBundleVersion") # 指定xcode打包 这里可选择不要,我们的项目需要用10.1版本xcode xcode_select("/Applications/Xcode_10.1.app") # 默认内测打包方式,目前支持app-store, package, ad-hoc, enterprise, development ipa_exportMethod = "ad-hoc" ipa_exportMethod_appStore = "app-store" # 计算buildNumber def updateProjectBuildNumber currentTime = Time.new.strftime("%Y%m%d") scheme_name = "项目名字" build = get_info_plist_value(path: "./#{scheme_name}/Info.plist", key: "CFBundleVersion").to_s 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 # 打包成功 jenkins 开始提示上传log # 使用fastlane上传蒲公英拿不到二维码展示, 所以使用jenkins上传蒲公英 def archiveSuccessLog(outputName,buildConfig) # 打好的包 移动到 jenkins的 workspace的目录下,用于jenkins上传蒲公英匹配包内容。永远只保留一份 # FileUtils.cp_r("#{$ipa_output_directory}" + "/#{outputName}", "#{$ipa_output_upload_directory}" + "/#{$jenkins_name}.ipa") puts" --------------------------------------------------------------------------" puts"| |" puts"| |" puts"| 🎉🎉🎉 --------->>>>> #{buildConfig}版本_打包成功 >>>> Jenkins 可以开始上传蒲公英了


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有