Jenkins+XCode9自动打包错误处理

背景

公司使用Jenkins+Xcode integration插件构建自动打包工具,在升级XCode9之后自动打包工具报错。错误信息如下所示:

xcodebuild[10696:413621] [MT] IDEDistribution: Step failed: <IDEDistributionSigningAssetsStep: 0x7fb3f664e8e0>: Error Domain=IDEDistributionSigningAssetStepErrorDomain Code=0 "Locating signing assets failed." UserInfo={NSLocalizedDescription=Locating signing assets failed., IDEDistributionSigningAssetStepUnderlyingErrors=(
    "Error Domain=IDEProvisioningErrorDomain Code=9 \"\"NAME.app\" requires a provisioning profile with the Push Notifications feature.\" UserInfo={NSLocalizedDescription=\"NAME.app\" requires a provisioning profile with the Push Notifications feature., NSLocalizedRecoverySuggestion=Add a profile to the \"provisioningProfiles\" dictionary in your Export Options property list.}"
)}
error: exportArchive: "NAME.app" requires a provisioning profile with the Push Notifications feature.

Error Domain=IDEProvisioningErrorDomain Code=9 ""NAME.app" requires a provisioning profile with the Push Notifications feature." UserInfo={NSLocalizedDescription="NAME.app" requires a provisioning profile with the Push Notifications feature., NSLocalizedRecoverySuggestion=Add a profile to the "provisioningProfiles" dictionary in your Export Options property list.}

原因

引用onevcat 大神的一句话:XCode9将不会允许你访问钥匙串里的内容,除非设置allowProvisioningUpdates。原文在这里,感兴趣的可以去阅读。

解决方案

自己动手写脚本替代插件(插件本质是帮助我们生成打包脚本代码)。对xcodebuild命令感兴趣的可以在terminal中输入man xcodebuild命令查看详细信息。

xcodebuild -archivePath "/Users/chaos/.jenkins/workspace/Project/output/debug/name.xcarchive" -workspace name.xcworkspace -sdk iphoneos -scheme "schemename" -configuration "Release" archive
xcodebuild -exportArchive -archivePath "/Users/chaos/.jenkins/workspace/Project/output/debug/name.xcarchive" -exportPath "/Users/chaos/.jenkins/workspace/Project/ipa/debug/" -exportOptionsPlist '/Users/chaos/.jenkins/workspace/Project/ipa/debug/ExportOptions.plist' -allowProvisioningUpdates

下面对脚本解释下:"/Users/chaos/.jenkins/workspace/Project"是本地代码文件所在路径(需要根据实际代码存放位置灵活改变)"output/debug/name.xcarchive"是存放archive生成的xcarchive类型文件的路径(name自定义,建议和工程名一致);-workspace name.xcworkspace -sdk iphoneos -scheme "schemename"(name&&schemename需要根据工程文件来自定义);
exportArchive就是上面xcarchive类型文件的存储路径;exportPath就是导出的ipa包存放的路径;exportOptionsPlist代表包含导出的ipa包的配置信息的文件存放路径;allowProvisioningUpdates就是获取访问钥匙串权限的关键所在,设置了这个字段就会在打包过程弹框请求获取钥匙串内容权限。
接着对ExportOptions.plist文件展开说明:

《Jenkins+XCode9自动打包错误处理》 屏幕快照 2017-09-29 03.48.05 PM.png

com.xx.cc代表Bundle ID,紧接着
ProfileName代表对应描述文件的name

《Jenkins+XCode9自动打包错误处理》 1506671685147.jpg

teamID的值可以在钥匙串中选中当前使用的证书查看。

《Jenkins+XCode9自动打包错误处理》 1506671976442.jpg

手动生成这样的plist文件过于麻烦,不如让XCode帮我们生成。使用XCode9打包并导出后的文件夹里就有这样一份文件可以直接拿过来用。

    原文作者:User106
    原文地址: https://www.jianshu.com/p/b3f883b51be3
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞