无法加载证书,Xcode构建无法安装证书(VSTS / Azure DevOps,YAML管道)

时间:2018-10-02 20:16:11

标签: ios xcode azure-devops

我在Azure DevOps中使用YAML管道来构建iOS应用。

我的YAML如下所示:

# Xcode
# Build, test, and archive an Xcode workspace on macOS.
# Add steps that install certificates, test, sign, and distribute the app, save build artifacts, and more:
# https://docs.microsoft.com/vsts/pipelines/languages/xcode

pool:
  vmImage: 'macOS 10.13'

steps:
- task: InstallAppleCertificate@2
  displayName: 'Install an Apple certificate'
  inputs:
    certSecureFile: 'FILE_ID'
    certPwd: '$(P12password)'

- task: InstallAppleProvisioningProfile@1
  displayName: 'Install an Apple provisioning profile'
  inputs:
    provProfileSecureFile: 'FILE_ID'

- task: CocoaPods@0
  displayName: 'pod install using the CocoaPods task with defaults'

- task: Xcode@5
  displayName: 'Xcode build'
  inputs:
    xcWorkspacePath: 'MyApp.xcworkspace'
    scheme: 'MyApp'
    xcodeVersion: 'Default'
    signingOption: manual
    signingIdentity: '$(APPLE_CERTIFICATE_SIGNING_IDENTITY)'
    provisioningProfileUuid: '$(APPLE_PROV_PROFILE_UUID)'

在“安装Apple证书”步骤中出现错误:

2018-10-02T20:08:23.4496940Z ##[section]Starting: Install an Apple certificate
2018-10-02T20:08:23.4786520Z ==============================================================================
2018-10-02T20:08:23.4786680Z Task         : Install Apple Certificate
2018-10-02T20:08:23.4786800Z Description  : Install an Apple certificate required to build on a macOS agent
2018-10-02T20:08:23.4786940Z Version      : 2.137.0
2018-10-02T20:08:23.4787050Z Author       : Microsoft Corporation
2018-10-02T20:08:23.4787160Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=862067)
2018-10-02T20:08:23.4787280Z ==============================================================================
2018-10-02T20:08:24.9657760Z [command]/usr/local/bin/openssl pkcs12 -in /Users/vsts/agent/2.140.2/work/_temp/PWEKQ6YCZA.p12 -nokeys -passin pass:*** | /usr/local/bin/openssl x509 -noout -fingerprint
2018-10-02T20:08:25.0196330Z 140735606010824:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:tasn_dec.c:1220:
2018-10-02T20:08:25.0197000Z 140735606010824:error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error:tasn_dec.c:386:Type=PKCS12
2018-10-02T20:08:25.0332040Z unable to load certificate
2018-10-02T20:08:25.0332600Z 140735606010824:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:697:Expecting: TRUSTED CERTIFICATE
2018-10-02T20:08:25.0437120Z ##[error]Error: /usr/local/bin/openssl failed with return code: 1
2018-10-02T20:08:25.0514080Z ##[section]Finishing: Install an Apple certificate

有什么主意在这里吗?

我还尝试通过UI在Azure DevOps中设置构建管道,但得到的结果相同。

4 个答案:

答案 0 :(得分:1)

您似乎像我一样一直关注this guide

问题似乎出在读取$(P12password)变量上。我尝试直接在安装Apple证书任务中输入证书密码,但不设置变量,并且没有更改。

希望我们可以一起改善这个答案,使其成为一个“解决方案”,而不仅仅是解决方法。

答案 1 :(得分:0)

为了允许任务读取变量,例如$(P12password),您需要链接变量组。 例如,对于构建管道,可以在用户界面的“编辑”模式下执行此操作。在“ YAML”标签旁边,您可以找到带有子项目“变量组”和按钮“链接变量组”的“变量”,该按钮可让您从库中选择一个。

发布管道的“变量”选项卡位于“任务”下拉菜单旁边。

详细信息:https://docs.microsoft.com/en-us/azure/devops/pipelines/library/variable-groups?view=azure-devops&tabs=yaml

答案 2 :(得分:0)

关于它的价值,我来到这里时遇到了这个确切的错误,但是通过确保证书密码没有特殊字符来解决了它。构建运行时,密码(尤其是£符号)的转义似乎存在问题。

答案 3 :(得分:0)

当 Azure 不知道如何访问变量时会出现此错误。

请注意,在下面的代码中,我们没有引用任何变量组:

pool:
  vmImage: 'macOS 10.13'

steps:
- task: InstallAppleCertificate@2
  displayName: 'Install an Apple certificate'
  inputs:
    certSecureFile: 'FILE_ID'
    certPwd: '$(P12password)'

所以当 Agent macOS 运行任务时,它没有密码,它与环境变量具有相同的概念。

为了完成这项工作,我们必须定义存储信息的变量组,如下所示:

pool:
  vmImage: 'macOS 10.13'
variables:
  - group: 'suitableVariableGroupName'
steps:
- task: InstallAppleCertificate@2
  displayName: 'Install an Apple certificate'
  inputs:
    certSecureFile: 'FILE_ID'
    certPwd: '$(P12password)'

请注意,变量组“suitableVariableGroupName”应该有一个名为:P12password 的变量,然后为其分配一个值。

相关问题