持续集成优点:
1、缩减开发周期,快速迭代版本
2、提供分发效率,测试人员以及相关人员无需等待开发人员打包
3、减少重复操作,高效打包,减轻开发人员工作量。
4 . 将代码推送到新的分支,CI 服务器就会为您运行测试。 如果 job 都是绿色 的,你的代码是 OK 的。
5 . 如果给定分支中的所有测试都是绿色的,则可以让 CI 服务器自动将代码部署到生产环境中。 这就是所谓的连续部署(Continuous Deployment) 。
6 . 减少 code review 时间
搭建方法
运行环境要求
- gitlab
- gitlabrunner
- fastlane
- 钉钉机器人
搭建步骤
1. 安装 gitlab runner
- Install GitLab Runner on macOS(我的是 mac 环境所以选择的 Install GitLab Runner on macOS)
*1.Download the binary for your system
1 | sudo curl --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-amd64 |
- 2.Give it permissions to execute:
1 | sudo chmod +x /usr/local/bin/gitlab-runner |
2. 注册 gitlab runner
- To register a Runner under macOS:
*1. Run the following command:
1 | gitlab-runner register |
- 2Enter your GitLab instance URL: (你 gitlab 的地址)
1 | Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com ) |
- Enter the token you obtained to register the Runner:(CI/CD 中项目的 token)
1 | Please enter the gitlab-ci token for this runner |
- Enter a description for the Runner, you can change this later in GitLab’s UI:
1 | Please enter the gitlab-ci description for this runner |
- Enter the tags associated with the Runner, you can change this later in GitLab’s UI:
1 | Please enter the gitlab-ci tags for this runner (comma separated): |
- 6 Enter the Runner executor:
1 | Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell: |
3. 编写 yml 文件
配置项目的 yml 文件进行相应的 job 操作
校验 yml 文件是否正确
本地调试 yml 文件
安装 jq 这个输出报告的时候用
1 | brew install jq |
下面是我的 yml 文件仅供参考
1 | //构建阶段 |
4. fastlane 构建
https://docs.fastlane.tools/getting-started/ios/setup/
(1)安装 xcode 命令行工具
- xcode-select –install,如果没有安装,会弹出对话框,点击安装。如果提示 xcode-select: error: command line tools are already installed, use “Software Update” to install updates 表示已经安装
#####(2) 安装 Fastlane
sudo gem install fastlane -NV 或是 brew cask install fastlane 我这里使用 gem 安装的
安装完了执行 fastlane –version,确认下是否安装完成和当前使用的版本号。
(3)初始化 Fastlane
cd 到你的项目目录执行
fastlane init
(4)打包到蒲公英
1 | fastlane add_plugin pgyer |
- 自己的 fastlane 脚本
1 |
|
5.钉钉通知
1 | #! bin/bash |
6 fastlane 构建注意事项(三天两头的加测试机,手动更新配置文件更新实在是太麻烦了,要不老是提示双重认证)
refer:https://blog.csdn.net/weixin_34293911/article/details/87011860
- fastlane iOS 双重认证 更新配置文件
这个时候就用到这个,他可以自动管理配置开发者等信息
https://github.com/fastlane/fastlane/tree/master/spaceship - 访问 AppleId 管理站
- 找到 安全 - App 专用密码,生成一个专用密码
- 配置环境变量 vim ~/.bash_profile
- export
1 | FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD=YOUR_PSD |
- 执行 fastlane spaceauth -u abcd@qq.com 按提示获取 session 信息。
- 复制 session 信息(很长一大段) 配置环境变量 vim ~/.bash_profile
1 | export FASTLANE_SESSION='YOUR SESSION' |