原文链接:http://www.jianshu.com/p/4364c7e0f6e8
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
前言 Continuous integration
CI 是敏捷开发的必备,简单说就是有这样一套工具,使得开发人员做好开发和单元测试再 push 代码后就不用管了,这套工具能自动地 check 代码的变化,自动 build, 自动做集成测试和场景测试等,自动部署到生产环境。
本文为iOS下的自动化打包,搭建可持续集成环境,省去给测试安装新版本的时间,提高工作效率。这里选择的方案是Jenkins+ Gitlab/Github+Xcode+Fir。
安装Jenkins
先安装homebrew,安装过的跳过这步
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
然后
$ brew install jenkins
若遇到
jenkins: Java 1.6+ is required to install this formula.
You can install with Homebrew Cask:
brew install Caskroom/cask/java
You can download from:
http://www.oracle.com/technetwork/java/javase/downloads/index.html
Error: An unsatisfied requirement failed this build.
按照提示安装java环境,推荐去java官网下载。
安装完成后浏览器会自动打开Jenkins页面(http://localhost:8080)
或输入
$ open /Applications/Jenkins/jenkins.war
若端口有冲突,则修改端口
$ defaults write /Library/Preferences/org.jenkins-ci httpPort yourport
再安装插件,在到jenkins页面,插件管理中安装以下插件
GIT plugin
GitHub plugin
Gitlab plugin
Post-Build Script Plug-in
Xcode integration
安装fir-cli,详细的参考文档
$ sudo gem install fir-cli
新建项目
新建一个项目,选择自由风格的软件项目。
![](https://i-blog.csdnimg.cn/blog_migrate/d451a2feb1230ba6ea5f5cff610cdf92.webp?x-image-process=image/format,png)
继续填写基本信息与源码管理,若选用Git则需注意填写Repositories地址与 Branches to build
![](https://i-blog.csdnimg.cn/blog_migrate/57643363234ff0d22fd261dac0885101.webp?x-image-process=image/format,png)
构建配置
添加构建触发器,这里就是告诉Jenkins什么时候自动构建。
![](https://i-blog.csdnimg.cn/blog_migrate/df14d126fa57f036b8fc17dfc0b43ae5.webp?x-image-process=image/format,png)
这里选择的是有push到github时构建,也可以选Poll SCM设置构建时间
![](https://i-blog.csdnimg.cn/blog_migrate/5bdafef4005b0683982d1073f43a0e6e.webp?x-image-process=image/format,png)
这里的配置为周一到周五每天8点到9点之间执行一次。
![](https://i-blog.csdnimg.cn/blog_migrate/bc59d0ea4d93b4e9542080fb440073ee.webp?x-image-process=image/format,png)
选择构建配置为Execute Shell,填入
fir build_ipa ${WORKSPACE1} -o ${WORKSPACE2}/TestJenkins.ipa -p -T #API Token#
- WORKSPACE1--------为项目路径
- WORKSPACE2--------ipa输出路径
- '#API Token#'--------fir API Token
然后保存退出。
构建
建议逐步构建,避免错误,构建历史如下
![](https://i-blog.csdnimg.cn/blog_migrate/2b2542933450cb33a5d4d5a54d4f1545.webp?x-image-process=image/format,png)
蓝色的为构建成功,红色为失败,若遇到以下类似的错误
PluginLoading: Required plug-in compatibility UUID F41BD31E-2683-44B8-
AE7F-5F09E919790E for plug-in at path '~/Library/Application Support/
Developer/Shared/Xcode/Plug-ins/KSImageNamed.xcplugin' not present in
DVTPlugInCompatibilityUUIDs
可以参考stackoverflow。
发布
构建成功后就可以在fir上看到应用了,扫码或打开短链接下载应用。
![](https://i-blog.csdnimg.cn/blog_migrate/25f0cb6949e3949e833dbb2c24d66d1c.webp?x-image-process=image/format,png)
注意这里只能安装开发者账号设备列表里的设备,个人开发者账号和企业账号有所区别
![](https://i-blog.csdnimg.cn/blog_migrate/26b14d717d61fc0ef9cfb2c9145e1443.webp?x-image-process=image/format,png)
详情可以查看fir support。