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

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

问题描述

随着Xcode 8的发布,苹果推出了一种管理签名配置的新方式。现在您有两个选项手动自动



根据WWDC 2016会议关于代码签名(WWDC 2016 - 401 - Xcode应用程序签名中的新功能),当您选择自动签名时,Xcode将执行以下操作:




  • 证书

  • 创建和更新应用程序ID

  • 创建和更新配置文件



但是根据苹果在那个会话中所说的,自动签名将使用开发签名

当您尝试使用自动签名时,在CI环境(如Travis CI或Jenkins)上。我不能找出一个简单的方法来保持使用自动和签署分发(因为Xcode强制你使用开发和Xcode创建的配置文件)。



新的Xcode创建的配置文件不显示在开发人员门户中,虽然我可以在我的机器上找到...应该将这些配置文件移动到CI机器,构建开发并导出 Distribution ?有没有办法重写自动签名使用 xcodebuild

解决方案

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




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




使用自动签名强制您使用开发人员证书和自动 - 生成供应配置文件。一个选项是将您的开发证书和私钥(Application - > Utilities - > Keychain Access)和自动生成的配置文件导出到CI计算机。找到自动生成的配置文件的方法是导航到〜/ Library / MobileDevice / Provisioning \ Profiles / ,将所有文件移动到备份文件夹,打开Xcode和归档项目。 Xcode将创建自动生成的开发配置文件并将其复制到 Provisioning Profiles 文件夹中。



xcodebuild archive ... 将为开发签名 .xcarchive xcodebuild -exportArchive ... 然后可以为分发

b

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




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



sed -i'''s / ProvisioningStyle = Automatic; / ProvisioningStyle = Manual; /'< ProjectName> .xcodeproj / project.pbxproj p>

@thelvis也创建了 Ruby脚本,使用 xcodeproj gem。



xcodebuild 会使用代码签名身份code> CODE_SIGN_IDENTITY ),以及配置配置文件( PROVISIONING_PROFILE_SPECIFIER )。这些设置也可以作为 xcodebuild 的参数提供,它们将覆盖项目中的代码签名身份和/或供应配置文件集。




  • 切换到手动签名




提供对所使用的代码签名身份和供应简档的完全控制。



有关使用Xcode 8进行代码签名的更多信息,我真的推荐这个文章以及WWDC2016会话 401 - Xcode应用程序签名的新功能


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

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:

  • Create signing certificates
  • Create and update App IDs
  • Create and update provisioning profiles

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.

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).

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?

解决方案

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

  • Include the Developer certificate and private key as well as the auto generated provisioning profiles in the CI environment:

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 ... will create a .xcarchive signed for Development. xcodebuild -exportArchive ... can then resign the build for Distribution

  • Replace 'Automatic' with 'Manual' when building on a CI environment

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;/' <ProjectName>.xcodeproj/project.pbxproj

@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 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.

  • Switch to manual signing

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.

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天全站免登陆