Teamcity - CI/CD - iOS - xcodebuild - signing - No signing certificate "iOS Development" found - ios

I have Teamcity installed with an Agent on a MAC. When I try to build the iOS project I have this error:
error: No signing certificate "iOS Development" found: No "iOS Development" signing certificate matching team ID "#######" with a private key was found. (in target 'App' from project 'App').
I use this command line:
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -workspace ios/App/App.xcworkspace -scheme App clean build
I did test the command in a terminal directly on the mac and it Works! My certificates are located in the keychain in the session of the user that runs the Agent of Teamcity.
I did try to put the certificate in another keychain and grant access to the process that is executed by Teamcity using this command :
security unlock-keychain -p [password] ~/Library/Keychains/teamcity.keychain-db
Any ideas?

Managed to solve this. The issue was that for some reason teamcity was looking at System keychain, and of course found nothing.
Adding certificate to the system keychain resolved this.

Related

Xcode signing using Jenkins

I am trying to sign and archive my Unity application with Jenkins. I have the Xcode jenkins plugin installed and everything seems to run well except for a strange problem.
During the xcodebuild phase, when the archive should be signed, I get the following error:
error: No signing certificate "iOS Development" found: No "iOS
Development" signing certificate matching team ID "QF6V2M666X" with a
private key was found. (in target 'Unity-iPhone')
Now the problem is that I am not trying to build for development, but for production. I have a production provisioning profile used, which is pointing the production certificate. The team id is the production team id (changed here for security reasons). Here is another part of the build output:
Going to invoke xcodebuild:, scheme: Unity-iPhone, sdk: DEFAULT,
project: DEFAULT, configuration: Release, clean: NO, archive:YES,
consolelog:YES, symRoot: DEFAULT, buildDir: DEFAULT,
developmentTeamID: QF6V2M666X
[sr-ios] $ /usr/bin/xcodebuild -scheme
Unity-iPhone -configuration Release archive -archivePath
When I open the project in Xcode, I can see that for some reason Xcode selects "IOSDeveloper" in the code signing identities part and not "IOSDistribution" (or the actual certificate in the provisioning profile):
I don't know if this can be changed from Jenkins, but I think Xcode should pick this up from the provisioning profile.
So I managed to find the problem and solve it, here is the solution for others.
In Unity 2018 they added a new option to the iOS player settings, in the "Other settings" section, called IOS Provisioning Profile->Profile type:
This option is used to select the signing identity. I guess you can use "Automatic" but in my case, since I am using Jenkins, I am setting it on a build script like this:
PlayerSettings.iOS.iOSManualProvisioningProfileType =
ProvisioningProfileType.Distribution;
When this option is set, xcode is able to sign the app correctly for distribution.

xcodebuild cannot find correct iOS Development Certificate under cron

I am currently using xcodebuild command line tool to build and deploy the app to iPhone as follows.
I saw in my login keychain that the iOS Development Certificate does exist but the key does not match Key1 as shown in the output. My question is how to allow xcodebuild to pick the correct iOS Development Certificate that is currently in the keychain.
Build Command
HOME=/Users/mcj xcodebuild build-for-testing -project ios/ios_test_app/HXKPIIOS/HXKPIIOS.xcodeproj -scheme HXKPIIOS -destination 'platform=iOS,id=<iPhoneUDID>' -derivedDataPath /opt/HX/HXKPI_Logs/kpi18_iOS_2018-06-23-21-20-01-149882/<iPhoneUDID>/build_derived_data | tee /opt/HX/HXKPI_Logs/kpi18_iOS_2018-06-23-21-20-01-149882/<iPhone UDID>/uitest/build1.log
Output
User defaults from command line:
IDEDerivedDataPathOverride = /opt/HX/HXKPI_Logs/kpi18_iOS_2018-06-23-21-20-01-149882/<iPhoneUDID>/build_derived_data
=== BUILD TARGET HXKPIIOS OF PROJECT HXKPIIOS WITH CONFIGURATION Debug ===
Check dependencies
Code Signing Error: No signing certificate "iOS Development" found: No "iOS Development" signing certificate matching team ID "<Key1>" with a private key was found.
Code Signing Error: Code signing is required for product type 'Application' in SDK 'iOS 11.2'
Go to the Project Navigator >> "General" tab. Look for the "Signing" section and you will see your Team, Provisioning Profile, Signing Certificate, and your Signing Status. Perhaps there is an issue with your Status as you were unable to sign in with your account. In that case, simply press Sign In... and re-enter your credentials. Or, perhaps, you are signed in on a team that does not have your Signing. In that case, go to the Team section and simply change which team you are signed in with. And finally, check your signing certificate in the Signing section. If its empty, that's why Xcode doesn't recognize your certificate.

ssh xcodebuild no signing certificate

When I try to build my app trough ssh with xcodebuild
xcodebuild -sdk iphoneos10.1 -target <app_target> -configuration Debug CODE_SIGN_IDENTITY="iPhone Developer" PROVISIONING_PROFILE=<profile> CONFIGURATION_BUILD_DIR=<some_dir>
It spits an error
No signing certificate "iOS Development" found: No
"iOS Development" signing certificate matching team ID "team_id"
with a private key was found. Code signing is required for product
type 'Application' in SDK 'iOS 10.1'
If I run it without ssh it builds.
The CODE_SIGN_IDENTITY is different than the "certificate_name". Shouldn't they be the same? The one I ask for is "iPhone Developer" and the build error is about "iOS Development".
I have tried this answer (if at all relevant to my problem).
When ssh-ed and I try security list-keychains it lists the system keychain twice. If I have not ssh-ed it shows the user login keychain-db as well.
I unlock the login keychain when ssh-ed to see if it will be displayed in the list and it is not.
Well the easiest solution was to copy the certificate from the login keychain to the system keychain. Don't know how secure or correct that is.
CODE_SIGN_IDENTITY should something like this:
iPhone Developer: Your Name (3374ZYXN2A)
You can find it in your Key Chain:
open Keychain Access
find your certificate
right-click it and choose "Get Info"
Copy the entry in "Common Name"

Cannot build project using xcodebuild, but can using Xcode.app

I am unable to make a build of my project using the xcodebuild command as it cannot find the singing identity for the development team. However, I can make a build using Xcode.app. This is the error I get with xcodebuild:
=== BUILD TARGET AppName OF PROJECT AppName WITH CONFIGURATION Release ===
Check dependencies
No signing certificate "iOS Development" found: No "iOS Development" signing certificate matching team ID "1234567890" with a private key was found.
The project settings define that the code signing identify for release builds is set to "iPhone Distribution":
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
DEVELOPMENT_TEAM = 1234567890;
And I can see the signing certificate and key in my keychain for that identify:
The build command I am using is:
xcodebuild \
-workspace "AppName.xcworkspace" \
-scheme "AppName (Release)" \
-destination generic/platform=iOS \
build
The scheme defines to build using release configuration.
As it happens I was logged in to the build server using SSH and when you log in to a mac using SSH the keychain is not unlocked automatically, therefor even though a certificate did exist, xcodebuild could not access it.
This question on Super User explains how you can unlock the keychain over ssh, or you can just use Terminal.app locally.

building xcode project from jenkins fails. when building in command line runs just fine. why?

building xcode project from jenkins fails.
when building in command line runs just fine.
why?
this is is the error I get:
[BEROR]Code Sign error: No matching provisioning profile found: Your build settings specify a provisioning profile with the UUID “_UUID_”, however, no such provisioning profile was found.
[BEROR]CodeSign error: code signing is required for product type 'Application' in SDK 'iOS 7.1'
this is the command line used:
xcodebuild -project PROJECTNAME.xcodeproj/ -target TARGETNAME -configuration Release -sdk iphoneos7.1 clean build
ps: anything with OBJECT was censored so this question can appear online, there was real data there before.
Are you using the login key-chain or did you create a different key-chain for jenkins builds app signing?
If you are just using the login key-chain make sure you unlock the key-chain during the build.
If you are using a different key-chain make sure you swap key-chains and then unlock it.
Jenkins - Xcode build works codesign fails - this thread is quite informative.
Also adding these 2 commands to your build can help you debug it:
/usr/bin/security list-keychains
/usr/bin/security find-identity

Resources