Fix the iOS code signing issue using Jenkins

This week I configure the Jenkins to work with Mac and try to build iOS applications. Unfortunately, I got the code signing issues, either I use Xcode plugin or Xcode command line tool. 

The core reason is Jenkins is running as daemon mode in Mac, just assume it is a different user – "Jenkins", so it will not have access to the keychain or provision profile as you log in using your credentials, which cause the code signing issue.

So we have 2 errors:

1. "Code Sign error: There are no valid certificate/private key pairs in the default keychain"
Solution: Copy your iPhone developer certificate from "login" keychain to "System" keychain.
Detailed steps:
  open the "Keychain Access" application, click the login tab, right-click the certificate like "iPhone Developer: your_name (XXXXXXX)", choose copy, then click the "System" tab, right click mouse, choose "Paste 2 items"; you might need to do the same thing with the certificate like "iPhone Distribution: your_name".

After doing this, you will get the second error.
2. "Code Sign error: Provisioning profile 'xxxxx-xxxx-xxxx-xxxxx' can't be found"
Solution: Copy the provisioning profile to Jenkins user folder.
The provisioning profile is under in the folder
/YourUser/Library/MobileDevice/Provisioning Profiles,
for example, on my machine, the provision profile files are under /Users/vovando/Library/MobileDevice/Provisioning Profiles
In the mac, the Jenkins will be in /Users/Jenkins, create the following folder:
/Users/Jenkins/Library/MobileDevice/Provisioning Profile,  then copy the .mobileprovision file to this folder.

After doing this, the code signing issues will be fixed.