Enviroment:
- Mac OS El Captain 10.11.4 (15E65)
- Xcode Version 7.3 (7D175)
- Mac OS Server Version 5.1 (15S5127)
I am struggling with a similiar issue and for me it boils down to two scenarios:
- sign the application with App Store Provisioning profile + Key - finishes without issues, no timeout
- sign the application with Add Hoc Provisioning profile + Key - times out on codesign
What actually times out in the end of the buildprocess is this command that creates an .ipa from .xcarchive:
xcodebuild -exportArchive -archivePath MyApp.xcarchive -exportPath ExportedProduct -exportOptionsPlist ExportOptions.plist -IDEPostProgressNotifications=YES -DVTAllowServerCertificates=YES -DVTSigningCertificateSourceLogLevel=3 -DVTSigningCertificateManagerLogLevel=3 -DTDKProvisioningProfileExtraSearchPaths=/Library/Developer/XcodeServer/ProvisioningProfiles -configuration Release
Content of the ExportOptions.plist is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-/
<plist version="1.0">
<dict>
<key>method</key>
<string>same-as-archive</string>
<key>onDemandResourcesAssetPacksBaseURL</key>
<string>http:/
<key>thinning</key>
<string><thin-for-all-variants></string>
</dict>
</plist>
Also I have given all the needed access for codesign to the private key located in the System keychain and went throough the web from end to end. Still, it fails.
Thing is that if you look carefully on the processes running on the Mac OS Server while your build is running then you can see that CI is working tirelessly with signing all your modules so it is not codesign key access issue its an issue of the fact that it is SLOW. Try it in terminal and see how the params for codesign change:
ps aux | grep _xcsbuildd | grep codesign
Command that is doing a codesign looks like this:
/usr/bin/codesign -vvv --force --sign 6BA79575D96E0826D4F7634FB36EBB93B0775378 --preserve-metadata=identifier,resource-rules --entitlements /var/folders/4r/4ll97s596wvfb6d39zt0hzhw000087/T/XcodeDistPipeline.Td3/entitlementsVnE /var/folders/4r/4ll97s596wvfb6d39zt0hzhw000087/T/XcodeDistPipeline.Td3/Root-iPhone\ 5s/Payload/MyApp.app
In my case this command is executed loads of times, all the frameworks used are signed (not just MyApp.app) and then all the possible output products are generated. In my manual xcodebuild command tests I am able to get all the result .ipa files and all I need to do is wait for 50 minutes... yes...:
drwxr-xr-x 19 myusername staff 646 Apr 19 11:25 .
drwxr-xr-x 5 myusername staff 170 Apr 19 11:25 ..
-rw-r--r-- 1 myusername staff 7617154 Apr 19 11:24 MyApp-iPad (4th generation)-etc.ipa
-rw-r--r-- 1 myusername staff 6588133 Apr 19 11:24 MyApp-iPad 2-etc.ipa
-rw-r--r-- 1 myusername staff 7404436 Apr 19 11:24 MyApp-iPad Pro (12.9-inch).ipa
-rw-r--r-- 1 myusername staff 7404233 Apr 19 11:24 MyApp-iPad Pro (9.7-inch).ipa
-rw-r--r-- 1 myusername staff 7404021 Apr 19 11:24 MyApp-iPad mini 3-etc.ipa
-rw-r--r-- 1 myusername staff 7404118 Apr 19 11:24 MyApp-iPad mini 4-etc.ipa
-rw-r--r-- 1 myusername staff 7617136 Apr 19 11:24 MyApp-iPhone 4S.ipa
-rw-r--r-- 1 myusername staff 7617505 Apr 19 11:24 MyApp-iPhone 5-etc.ipa
-rw-r--r-- 1 myusername staff 7404396 Apr 19 11:24 MyApp-iPhone 5s.ipa
-rw-r--r-- 1 myusername staff 8617369 Apr 19 11:25 MyApp-iPhone 6 Plus.ipa
-rw-r--r-- 1 myusername staff 7404458 Apr 19 11:24 MyApp-iPhone 6.ipa
-rw-r--r-- 1 myusername staff 8617501 Apr 19 11:24 MyApp-iPhone 6s Plus.ipa
-rw-r--r-- 1 myusername staff 7404598 Apr 19 11:24 MyApp-iPhone 6s.ipa
-rw-r--r-- 1 myusername staff 7404615 Apr 19 11:24 MyApp-iPhone SE.ipa
-rw-r--r-- 1 myusername staff 7404305 Apr 19 11:24 MyApp-iPod touch (6th generation).ipa
-rw-r--r-- 1 myusername staff 7617300 Apr 19 11:24 MyApp-iPod touch.ipa
-rw-r--r-- 1 myusername staff 17117216 Apr 19 11:25 MyApp.ipa
So in my case the issue lies in the /user/bin/codesign command being utterly slow signing loads of files it needs to sign when Xcode Server is running an integration on a Bot. Here is an example execution done on two accounts. One account is the one that XCode Server is using called _xcsbuildd located in /var/_xcsbuildd (not /Users as you might expect) and the other is executed with a general user that has his stuff in /Users folder.
_xcsbuildd codesign:
bash-3.2$ time /usr/bin/codesign -vvv --force --sign 6BA79575D96E0826D4F7634FB36EBB93B0775378 --preserve-metadata=identifier,resource-rules --entitlements /var/folders/4r/4ll97s596wvfb6d39zt0hzhw000087/T/XcodeDistPipeline.Td3/entitlementsVnE /var/folders/4r/4ll97s596wvfb6d39zt0hzhw000087/T/XcodeDistPipeline.Td3/Root-iPhone\ 5s/Payload/MyApp.app
Warning: usage of --preserve-metadata with option "resource-rules" (deprecated in Mac OS X >= 10.10)!
/var/folders/4r/4ll97s596wvfb6d39zt0hzhw000087/T/XcodeDistPipeline.Td3/Root-iPhone 5s/Payload/MyApp.app: replacing existing signature
/var/folders/4r/4ll97s596wvfb6d39zt0hzhw000087/T/XcodeDistPipeline.Td3/Root-iPhone 5s/Payload/MyApp.app: signed app bundle with Mach-O thin (arm64) [com.myapp]
real 0m7.261s
user 0m3.950s
sys 0m0.638s
myusername codesign:
bash-3.2$ time /usr/bin/codesign -vvv --force --sign 6BA79575D96E0826D4F7634FB36EBB93B0775378 --preserve-metadata=identifier,resource-rules --entitlements /var/folders/4r/4ll97s596wvfb6d39zt0hzhw000087/T/XcodeDistPipeline.Td3/entitlementsVnE /var/folders/4r/4ll97s596wvfb6d39zt0hzhw000087/T/XcodeDistPipeline.Td3/Root-iPhone\ 5s/Payload/MyApp.app
Warning: usage of --preserve-metadata with option "resource-rules" (deprecated in Mac OS X >= 10.10)!
/var/folders/4r/4ll97s596wvfb6d39zt0hzhw000087/T/XcodeDistPipeline.Td3/Root-iPhone 5s/Payload/MyApp.app: replacing existing signature
/var/folders/4r/4ll97s596wvfb6d39zt0hzhw000087/T/XcodeDistPipeline.Td3/Root-iPhone 5s/Payload/MyApp.app: signed app bundle with Mach-O thin (arm64) [com.myapp]
real 0m0.730s
user 0m0.304s
sys 0m0.042s
Same command, same input parameters and 10x the time for single codesign execution and as mentioned above, those codesign calls are executed maybe 50 times per single intergation so when you multiply that by 7 seconds per condesign you get a timeout on the CI. I can set the timout on the CI to be 2 hours for a build, but does it make sense? Huh. When you add the fact that Xcode server is unable to do concurrent builds you end up with a CI stuck for a long time.
To wrap up the issue is happening on the CI only building with Add Hoc provisioning profile, works fine with App Store provisioning profile and the culprit in my case is the really slow codesign command execution only on the _xcsbuildd user. How unix user account can be connected to a single codesign running time is a mystery for me.
I am still stuck with manual singing of the apps to test for my testers which is annoying and time consuming. Seriously thinking about moving to Jenkins and using some third party software that does its job better then Apple's which is a disgrace.