Code signing error running XCodeBuild in Jenkins

喜夏-厌秋 提交于 2019-12-04 07:13:06

I feel for you as the last time we messed with this it was quite the challenge. We did this when we set up a CI server for a project. If I remember correctly (broadly) we followed these steps:

1) Set Jenkins up as a developer on the Apple Dev account

2) Created a cert and dev provisioning profile specifically for Jenkins

3) Setup a Jenkins user on the CI Server and delete any previous certs/prov profiles from xcode for that user

4) Add the Jenkins cert to the AD-Hoc Dist Profile (If you are trying to distribute an .ipa to HockeyApp you will need to to this for an archive build.)

5) Go into the xcode project file and delete any existing references to Provisioning Profiles

6) Download and Install the certs for this user and the appropriate Prov Profiles.

7) Before the build unlock the Jenkins user keychain. Do this only if the Jenkins user is not the user running the xcode build.

Verify that Xcode shows the Prov Profile as valid in the organiser when logged in as the Jenkins user.

I know my answer is somewhat vague and my intent is to be helpful. This type of error is usually caused by one of three things. Xcode cant find the profile, Xcode cant find the cert or Xcode found more then one profile (supposed to produce a different error but doesn't always) and has a mismatch of some kind. Usually redoing the Prov Profiles is the least painful solution.

Best of luck man. You will solve it it's just a huge headache!

Probably not the answer you are looking for, but i gave up on the XCodeBuild plugin for a number of reasons, and running my build through "Execute Shell" step.

You said your command line build works, so you already know the commands that are required. Just put that into the shell.

xcodebuild -verbose -alltargets -configuration Debug clean build CODE_SIGN_IDENTITY="${CODE_SIGN_IDENTITY}" PROVISIONING_PROFILE=${PROVISIONING_PROFILE}
&&
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "${WORKSPACE}/client_trunk/build/Debug-iphoneos/${Application}.app" -o "${WORKSPACE}/client_trunk/build/Debug-iphoneos/${Application}-Debug-${shortVer}.${revVer}.ipa" --sign "${CODE_SIGN_IDENTITY}" --embed "/Users/[youruser]/Library/MobileDevice/Provisioning Profiles/${PROVISIONING_PROFILE}.mobileprovision"

Above, ${CODE_SIGN_IDENTITY} is the one that looks like iPhone Developer: blah
And ${PROVISIONING_PROFILE} is the hex number for the profile like F152C66E-B99A-47F6-B262-376CE4403D71

Using Jenkins I got this error:

/Users/Shared/Jenkins/Home/jobs/ExampleTabbed-Integration/workspace/build/Debug-iphoneos/ExamplesTabbed.app: User interaction is not allowed.

Command /usr/bin/codesign failed with exit code 1

I fixed it by doing the following:

  • Add Build Step before the XCode (jenkins plugin) step
  • Add the following as the execute command:

    security unlock-keychain -p "passwordhere" ${HOME}/Library/Keychains/login.keychain

  • In the XCode (via plugin) configuration I'm using the following:

    • Unlock Keychaing ? (unchecked)
    • Keychain path: ${HOME}/Library/Keychains/login.keychain
    • Keychain password: (empty)

It might be possible to remove the pre-step and use the actual xcode config to do it, but it's working as described with no problems.

Note this doesn't take into account using a more secure solution yet, but this was my solution to the xcode signing issue. I'm running on OSX with the Jenkins installer and running as a launchctl command, used by the default Jenkins installer application. If that helps.

Follow instruction on the Xcode Plugin home page :

If this prompt is not showing on the build machine, you can force it to appear by running the codesign command that failed from a terminal on the build machine: /usr/bin/codesign --force --sign "iPhone Distribution: .....

Execute failed signing command from the terminal as a Jenkins user and select "Always allow"

Subprocesses of Java/Jenkins will need to have unlocked access to the Keychain.

Let's say your build / code-sign / release process is working fine. The only blocker is when you try running the exact same process in Jenkins.

Chances are that the keychain is locked, not for the user, but for Jenkins sub-processes.

The security command to unlock the keychain will need to be run as a Jenkins job, just once. Even if the same logged in user has already unlocked the keychain in the terminal.

So setup a simple freestyle job in Jenkins and add the following shell command as a build phase.

security unlock-keychain -p PASSWORD /Users/your_username/Library/Keychains/login.keychain-db

(make sure you include the proper PASSWORD and path to login.keychain-db)

Once you've run this job once, try your regular release job again, it should work if you have all the required apple certificates in your login keychain.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!