持续集成方案
- Jenkins + Fastlane
- gitlab + Fastlane
1.Jenkins + Fastlane
参考:https://www.jianshu.com/p/ae5b492b5338
2.gitlab + Fastlane
1. 下载安装gitlab runner
- 参考 https://docs.gitlab.com/runner/install/
2. 下载安装fastlane
- 参考 https://docs.fastlane.tools/getting-started/ios/setup/
- cd 到工作目录 fastlane init 当前路径下会出现一个fastlane/,下面有两个配置文件,Appfile和Fastfile
3. 配置 fastlane 自动化打包
default_platform(:ios)
platform :ios do
desc "Push a new beta build to TestFlight"
before_all do
#配置特殊密码跳过苹果二次验证
ENV["FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD"] = "xxxxxxx"
desc "pod install"
end
# 打包上传蒲公英
lane :pgyer_Hoc do
cert
sigh(adhoc:true,force:true)
cocoapods(verbose:true,use_bundle_exec:false,try_repo_update_on_error:true,podfile: "Podfile")
build_app(workspace: "xxxx.xcworkspace", scheme: "xxxxx",clean:true,export_method: "ad-hoc")
pgyer(api_key: "xxxxx", user_key: "xxxxx")
end
# 运行测试用例
lane :tests do
cocoapods(verbose:true,use_bundle_exec:false,try_repo_update_on_error:true,podfile: "Podfile")
run_tests(
workspace: "xxxx.xcworkspace",
scheme: "xxxxTest",
devices: ["iPhone 8"],
clean:true,
fail_build:false,
code_coverage:true,
reinstall_app:true,
app_identifier:"com.xxxx.xxxx",
output_types:"html",
output_files: "xxxxTest.html")
end
# 计算测实用率覆盖率
lane :test_xcov do
xcov(
workspace: "xxxx.xcworkspace",
scheme: "xxxxTest",
output_directory: "fastlane/xcov_output",
markdown_report:true,
include_test_targets:true,
only_project_targets:true) #只显示主项目覆盖率
end
# 打包上传TestFlight
lane :beta_Testflight do
cert
sigh
build_app(workspace: "xxxx.xcworkspace", scheme: "xxxx",clean:true)
ENV["DELIVER_ITMSTRANSPORTER_ADDITIONAL_UPLOAD_PARAMETERS"] = "-t Aspera"
upload_to_testflight(skip_waiting_for_build_processing:true)
end
end
4. 配置.gitlab-ci.yml
stages:
- pgyer
- unitTest
- testFlight
variables:
LANG: "en_US.UTF-8"
LANGUAGE: "en_US.UTF-8"
LC_ALL: "en_US.UTF-8"
pgyer_job:
stage: pgyer
script:
- fastlane init
- fastlane pgyer_Hoc
tags:
- app_runner
only:
- develop
tests_job:
stage: unitTest
script:
- fastlane init
- fastlane tests
- fastlane test_xcov
- ./auto-dev.sh
tags:
- app_runner
only:
- develop
testFlight_job:
stage: testFlight
script:
- fastlane init
- fastlane beta_Testflight
- ./auto.sh #执行脚本 发送钉钉通知、邮件通知等
tags:
- app_runner
only:
- release_build
5.苹果持续集成难点
1.由于账号有两步验证,避免两步验证需要在苹果开发平台申请特殊密码
- 通过环境变量FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD提供这个application specific password。
- 执行fastlane spaceauth -u user@email.com,生成session cookie。
- 通过环境变量FASTLANE_SESSION提供session cookies。配置环境变量 vim ~/.bash_profile
2.该方案,每个月会过期需要重新生成session
参考
- https://www.jianshu.com/p/19ae8cc865b0
- https://segmentfault.com/a/1190000011717578?utm_source=tuicool&utm_medium=referral