在 CI (Travis/Jenkins) 环境中使用 xcodebuild (Xcode 8) 和自动签名 [英] Use xcodebuild (Xcode 8) and automatic signing in CI (Travis/Jenkins) environments

查看:22
本文介绍了在 CI (Travis/Jenkins) 环境中使用 xcodebuild (Xcode 8) 和自动签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着 Xcode 8 的发布,Apple 引入了一种管理签名配置的新方法.现在您有两个选项 ManualAutomatic.

With the release of Xcode 8, Apple introduced a new way of managing the signing configuration. Now you have two options Manual and Automatic.

根据关于代码签名的 WWDC 2016 会议 (WWDC 2016 - 401 - What's new在 Xcode 应用程序签名中),当您选择 Automatic 签名时,Xcode 将:

According to the WWDC 2016 Session about Code signing (WWDC 2016 - 401 - What's new in Xcode app signing), when you select Automatic signing, Xcode is going to:

  • 创建签名证书
  • 创建和更新应用 ID
  • 创建和更新配置文件

但根据 Apple 在该会议上所说的,Automatic Signing 将使用 Development Signing 并将仅限于 Xcode 创建的配置文件.

But according to what Apple says in that session, the Automatic Signing is going to use Development signing and will be limited to Xcode-created provisioning profiles.

当您尝试在 CI 环境(如 Travis CI 或 Jenkins)上使用 Automatic Signing 时,问题就会出现.我无法找到一种简单的方法来继续使用 Automatic 和 Sign for Distribution(因为 Xcode 强制您使用开发和 Xcode 创建的配置文件).

The issue comes when you try to use Automatic Signing on a CI environment (like Travis CI or Jenkins). I'm not able to figure out an easy way to keep using Automatic and sign for Distribution (as Xcode forces you to use Development and Xcode-created provisioning profiles).

新的Xcode 创建的配置文件"没有显示在开发人员门户中,虽然我可以在我的机器中找到...code> 并导出 Distribution?有没有办法使用 xcodebuild 覆盖 Automatic Signing?

The new "Xcode-created provisioning profiles" do not show up in the developer portal, although I can find then in my machine... should I move those profiles to the CI machine, build for Development and export for Distribution? Is there a way to override the Automatic Signing using xcodebuild?

推荐答案

在尝试了几个选项后,这些是我能够在我的 CI 服务器上使用的解决方案:

After trying a few options, these are the solutions that I was able to use on my CI server:

  • 在 CI 环境中包含开发者证书和私钥以及自动生成的配置文件:

使用自动签名 强制您使用Developer 证书和自动生成的配置文件.一种选择是将您的开发证书和私钥(应用程序 -> 实用程序 -> 钥匙串访问)以及自动生成的配置文件导出到 CI 机器.找到自动生成的配置文件的一种方法是导航到 ~/Library/MobileDevice/Provisioning Profiles/,将所有文件移动到备份文件夹,打开 Xcode 并存档项目.Xcode 将创建自动生成的开发配置文件,并将它们复制到 Provisioning Profiles 文件夹.

Using Automatic signing forces you to use a Developer certificate and auto-generated provisioning profiles. One option is to export your development certificate and private key (Application -> Utilities -> Keychain Access) and the auto-generated provisioning profiles to the CI machine. A way to locate the auto-generated provisioning profiles is to navigate to ~/Library/MobileDevice/Provisioning Profiles/, move all files to a backup folder, open Xcode and archive the project. Xcode will create auto-generated development provisioning profiles and will copy them to the Provisioning Profiles folder.

xcodebuild archive ... 将创建一个为 Development 签名的 .xcarchive.xcodebuild -exportArchive ... 然后可以为 Distribution

xcodebuild archive ... will create a .xcarchive signed for Development. xcodebuild -exportArchive ... can then resign the build for Distribution

  • 在 CI 环境中构建时将自动"替换为手动"

在调用 xcodebuild 之前,解决方法是将项目文件中 ProvisioningStyle = Automatic 的所有实例替换为 ProvisioningStyle = Manual.sed 可用于在 pbxproj 文件中进行简单的查找替换:

Before calling xcodebuild a workaround is to replace all instances of ProvisioningStyle = Automatic with ProvisioningStyle = Manual in the project file. sed can be used for a simple find an replace in the pbxproj file:

sed -i '' 's/ProvisioningStyle = Automatic;/ProvisioningStyle = Manual;/' .xcodeproj/project.pbxproj

@thelvis 还创建了一个 Ruby 脚本来使用 xcodeproj代码> 宝石.该脚本可让您更好地控制更改的内容.

@thelvis also created a Ruby script to do this using the xcodeproj gem. The script gives you a better control over what is changed.

xcodebuild 然后将使用项目中设置的代码签名标识 (CODE_SIGN_IDENTITY),以及配置文件 (PROVISIONING_PROFILE_SPECIFIER).这些设置也可以作为参数提供给 xcodebuild,它们将覆盖项目中设置的代码签名标识和/或配置文件.

xcodebuild will then use the code signing identity (CODE_SIGN_IDENTITY) set in the project, as well as the provisioning profiles (PROVISIONING_PROFILE_SPECIFIER). Those settings can also be provided as parameters to xcodebuild and they will override the code signing identity and/or provisioning profile set in the project.

使用 Xcode 9,xcodebuild 有一个新的构建设置参数 CODE_SIGN_STYLE 以在 AutomaticManual 之间进行选择> 所以没有必要在项目文件中查找和替换自动的实例,更多信息在 WWDC 2017 Session 403 Xcode 和 Xcode Server 签名的新功能

with Xcode 9, xcodebuild has a new build settings parameter CODE_SIGN_STYLE to select between Automatic and Manual so there's no need to find and replace instances of automatic with manual in the project file, more info in WWDC 2017 Session 403 What's New in Signing for Xcode and Xcode Server

  • 切换到手动签名

  • 手动签名将提供对正在使用的代码签名身份和配置文件的完全控制.这可能是最干净的解决方案,但缺点是失去了自动签名的所有好处.

    Manual signing will provide total control over the code signing identities and provisioning profiles being used. It's probably the cleanest solution, but with the downside of losing all the benefits of Automatic signing.

    要了解有关使用 Xcode 8 进行代码签名的更多信息,我强烈推荐这篇文章以及WWDC2016 会议 401 - Xcode 应用签名的新功能

    To learn more about code signing with Xcode 8 I really recommend this article as well as the WWDC2016 session 401 - What's new in Xcode app signing

    这篇关于在 CI (Travis/Jenkins) 环境中使用 xcodebuild (Xcode 8) 和自动签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆