iOS Jenkins + fastlane自动打包,蒲公英上
前言
自动化历程:
网上文章很多,但是大多都不是特别详细,按照上面步骤来,大多都走不通,所以才写出了这篇文章,以方便自己以后使用
1、初识fastlane,在第一次了解fastlane时候,感觉很方便,但是看了很多网上教程,始终不得入门
2、初识 Jenkins,在前段时间,我的Android小伙伴问题使用没使用Jenkins,我楞了一下,决定问题啥是Jenkins,然后了解后,我感觉别人有的我也要!经过查看网上教程和多次实践,始终都是失败,不过倒是实现了使用fastlane进行自动化打包,最终决定,自己开心就好,还是不要和别人攀比了。
3、过了一段时间,还是咽不下这口气,查看Jenkins错误报告和各种实践,最终成功构建。Jenkins打包成功
前置工作
要做Jenkins自动打包,要配合fastlane来使用(不知道别人怎么处理的,不过我这边是这么做的)
关于 fastlane、以及蒲公英插件配置使用,看下面这篇文章
iOS fastlane 自动打包,上传蒲公英
1、安装 jenkins
brew install jenkins
卸载可以把 install 替换成 uninstall就可以了
brew uninstall jenkins

命令行安装成功后 启动 jenkins
启动 jenkins: brew services start jenkins
停止 jenkins:brew services stop jenkins
重启 Jenkins:brew services restart jenkins

2、jenkins配置
2.1 打开浏览器,进入到 jenkins 初始化
此时可使用 http://localhost:8080 访问 jenkins 进入 \Jenkins\secrets 目录,打开 initialAdminPassword 文件复制出密码即可

2.2 安装插件
然后安装推荐的插件:此处默认就好

安装 jenkins 推荐通用的插件 接下来是漫长的等待
等完成之后,选择系统管理 - 管理插件。
安装 GitLab 插件
在可选插件中选择 GitLab Plugin 和 Gitlab Hook Plugin 进行安装。
安装 Xcode 插件
在可选插件中选择 Xcode integration 进行安装。

2.3 环境变量配置
去到 系统管理 -> 系统设置 -> 全局属性 -> 环境变量 中的环境变量进行配置
其中键固定 PATH
值:终端输出值:(echo $PATH)获取

3、创建任务
3.1 新建任务
选择新建任务,输入任务名称,选择第一个,构建一个自由风格的软件项目

3.2 配置任务
3.2.1 源码管理
- 选择Git 在 repository URL 添加你的git地址
-
在Branches to build 填写你的指定git分支
31.png
3.2.2 构建环境
此处是重点,我的大多失败历程都是因为这块没有处理好
选择 执行shell
#!/bin/bash
echo -e "=========安装更新pod==========="
pod install
echo -e "=======打包上传======="
fastlane app

4 立即构建
上面配置完毕之后,回到任务中,点击立即构建,下面会有一个执行的进度条, 很抱歉我失败了36次,最后才成功
立即执行前提:
1、构建的项目,拉取到制定的jenkins的workspace中,能进行fastlane自动打包


遇到问题
1.pod install 问题
也是网上提出最多的 Build step 'Execute shell' marked build as failure 问题
1.1、如果没有3.2.2 执行shell,jenkins 只会从git上拉取代码, 我的第一个问题一直失败到这里,如下图所示,仅仅是代码,没有三方库的pods文件
1.2、虽然我项目可以fastlane app执行,但是下面拉取的代码,无论通过jenkins还是 fastlane 都没法自动打包,所以我在shell添加了 pod install
1.3 只添加pod install 并没法执行,所以我添加了pod install 上面三行代码

2. 组件化遇到问题
也就是第一个问题中的1.2,如下图
git仓库没办法拉取指定组件代码,把下面未注释代码,改成已经注释的,指定git地址和 提交commit,就能拉取了
但是整体拉说,jenkins 对组件化来说不如 fastlane 使用方便

报错截图

最后,完结散花🎉🎉🎉
参考文章
Jenkins+Fastlane + 蒲公英 + 钉钉