1 安装 Gitlab runner
# 使用brew安装
$ brew install gitlab-runner
# 找到安装路径
$ brew list gitlab-runner
# 给 Gitlab runner的路径 添加运行权限
$ sudo chmod +x /opt/homebrew/Cellar/gitlab-runner
推荐安装 xcpretty 支持 编译 信息友好显示
2 准备Runner token
Gitlab项目需要 master 权限,打开 Setting -> CI/CD,点击 Runner Settings 后面的 Expand,找到URL和Registration token
3 Gitlab runner 注册
$ gitlab-runner register # 这里不推荐使用 sudo 提权, 否则不会连接到 GitLab 上
WARNING: Running in user-mode.
WARNING: Use sudo for system-mode:
WARNING: $ sudo gitlab-runner...
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
https://你的 Gitlab 地址/ #步骤2中准备的URL
Please enter the gitlab-ci token for this runner:
dajFZ111111113FSxGC #步骤2中准备的token
Please enter the gitlab-ci description for this runner:
[hostame] my-runner
Please enter the gitlab-ci tags for this runner (comma separated):
BuildTag,my-tag
Whether to run untagged builds [true/false]:
[false]: true
Whether to lock the Runner to current project [true/false]:
[true]: true
Registering runner... succeeded runner=GSoLCqQw
(http://gitlab.sz.xxxxxcloud/runners/9) <small class="edit-runner" style="box-sizing: border-box; font-size: 16.8px; font-weight: 400; color: rgb(46, 46, 46);">[](http://gitlab.sz.xxxxxcloud.com/iOS_APPS/mycloud/runners/9/edit)</small>
[暂停](http://gitlab.sz.xxxxxcloud.com/iOS_APPS/mycloud/runners/9/pause)
Please enter the executor: docker, parallels, ssh, virtualbox, docker+machine, docker-ssh+machine, docker-ssh, shell, kubernetes:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
$ gitlab-runner install
$ gitlab-runner start
完成设置后,可通过 vi ~/.gitlab-runner/config.toml
打开 runner 的配置文件进行修改。
install配置修改目录 /Users/xxx/Library/LaunchAgents/gitlab-runner.plist
接下来重启 gitlab-runner 后就可以在 gitlab 里看到设置好的 runner,并可以进行修改
4 配置 .gitlab-ci.yml 文件
进入gitlab项目 点击 CI/CD配置
编写.gitlab-ci.yml 文件
stages:
- archive
archive_project:
stage: archive
script:
- export LANG=en_US.UTF-8 # for xcpretty or pod install
- tagName=$CI_COMMIT_TAG
# M1 Mac 打包会显示当前设备未注册,可以注册M1设备 或者 添加 -destination 'generic/platform=iOS'
# M1 Mac 导出失败 添加 arch -x86_64
- xcodebuild -workspace "$PWD/Test.xcworkspace" -scheme "${scheme}" -configuration "Release" -archivePath ".build/${name}.xcarchive" -allowProvisioningUpdates -destination 'generic/platform=iOS' clean archive DWARF_DSYM_FOLDER_PATH=${dSYMPath} | xcpretty -s
- arch -x86_64 xcodebuild -exportArchive -archivePath ".build/${name}.xcarchive" -exportPath "${archivePath}" -exportOptionsPlist "/Users/xxx/Workspace/ExportOptions_enterprise.plist" -allowProvisioningUpdates YES | xcpretty -s
- curl -F "file=@${IPA_PATH}" -F "_api_key=${apiKey}" http://www.pgyer.com/apiv2/app/upload
artifacts:
paths:
# - .build/Test
# expire_in: 2 h
only:
- tags # 只有 Gitlab 添加 Tag 时触发 Runner
tags:
- TestTag
❗️遇到的问题
M1的Mac 导出ipa遇到"IPA Processing Failed"
在导出命令前加上 $ arch -x86_64
Xcode或终端遇到此问题时:
1 Xcode -->Build Settings -->iOS Deployment Target-->iOS 13.0 or later
2 或者 对Xcode或终端 勾选使用Rosetta打开
shell 修改文件内容失败, 需要提权,以下方法任选一种
1 使用sudo命令执行脚本 echo "password" | sudo -S mkdir "$archivePath"
2 执行脚本前先对目录提权 chmod +x $archivePath
3 把操作的目录放到$ User/Shared下
log输出上限
在~/.gitlab-runner/config.toml
中修改 output_limit = 10000
, 默认值是4096
Your session has expired. Please log in.
删除钥匙串里的Apple Worldwide Developer Relations Certification Authority,清除Xcode缓存并重启
DVTPortal: Error: Error Domain=DVTPortalServiceErrorDomain Code=1100 "Your session has expired. Please log in."
通过 Xcode 首选项删除帐户
退出 Xcode
在终端中,将首选项设置为不使用钥匙串服务:defaults write com.apple.dt.Xcode DVTDeveloperAccountUseKeychainService_2 -bool NO
重新打开 Xcode 并重新添加帐户
参考资料
https://www.jianshu.com/p/c835adc414ed
https://www.jianshu.com/p/3c0cbb6c2936
https://blog.csdn.net/afei__/article/details/82413724
https://segmentfault.com/a/1190000010442764
https://blog.csdn.net/weixin_36225424/article/details/113451656
https://docs.gitlab.com/ee/ci/variables/predefined_variables.html