Codesign fails during xcodebuild archive in Bamboo only - ios

I have a script that builds and archives an iOS App using xcodebuild. Running it manually on the CI server works perfectly, but it always fails if run as a task in Bamboo:
/Users/bamboo/Library/Developer/Xcode/DerivedData/MyApp-fznnexbqdbnwoebohwwvajvtmcdf/Build/Intermediates/ArchiveIntermediates/LIVE/InstallationBuildProductsLocation/Applications/MyApp.app: unknown error -1=ffffffffffffffff
Command /usr/bin/codesign failed with exit code 1
** ARCHIVE FAILED **
the archive command looks like this:
xcodebuild -workspace "${workspace}" -scheme "${scheme}" -archivePath "${archive_path}" clean archive
I did try:
using security unlock-keychain before the xcodebuild command
chaining security unlock-keychain and xcodebuild commands with &&
manually unlocking keychain
moving the signing certificate and key to System keychain
setting Allow all applications to access this item in keychain
searching SO and everything else (even asking the janitor :) )
If this is of any help, the project uses manual signing, the profile and certificate are specified in build settings because those change quite often, nevertheless the logs show that the right signing identity is picked up.
Any suggestions of what could be wrong are welcome.

Open Terminal and paste this two:
cd ~/Library/Developer/Xcode/DerivedData
xattr -rc .

Related

Building Xcode project with Jenkins gives codesign error

I'm trying to build Xcode project with Jenkins. Project for Xcode generated by Unity Engine.
I am able to build this project directly from Xcode GUI, but when trying to build project through Jenkins i'm getting following error at the end of build:
Signing Identity: "iPhone Developer: MyName MySurname (XXXXXXXXXX)"
Provisioning Profile: "iOS Team Provisioning Profile: *"
(XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX)
/usr/bin/codesign --force --sign 37DF6AF254E5A4856B1BA024D199DEE3CE596A58 --entitlements /Users/Shared/Jenkins/Home/workspace/Xcode_Input/build/Unity-iPhone.build/Release-iphoneos/Unity-iPhone.build/myapplication.app.xcent --timestamp=none /Users/Shared/Jenkins/Home/workspace/Xcode_Input/build/Release-iphoneos/myapplication.app
/Users/Shared/Jenkins/Home/workspace/Xcode_Input/build/Release-iphoneos/myapplication.app: errSecInternalComponent
Command CodeSign failed with a nonzero exit code
** BUILD FAILED **
The following build commands failed:
CodeSign /Users/Shared/Jenkins/Home/workspace/Xcode_Input/build/Release-iphoneos/myapplication.app
(1 failure)
Build step 'Xcode' marked build as failure
Finished: FAILURE
I tried to reproduce following command in terminal, and it woked fine without any errors:
/usr/bin/codesign --force --sign 37DF6AF254E5A4856B1BA024D199DEE3CE596A58 --entitlements /Users/Shared/Jenkins/Home/workspace/Xcode_Input/build/Unity-iPhone.build/Release-iphoneos/Unity-iPhone.build/myapplication.app.xcent --timestamp=none /Users/Shared/Jenkins/Home/workspace/Xcode_Input/build/Release-iphoneos/myapplication.app
It asked me for my password two times(and same password specified in Jenkins job settings for Xcode), and finished without any errors.
Keychain i used to sign project is unlocked with: security unlock-keychain login.keychain
The question is - what could be the reason of following behavior? How can i solve this problem?
Thanks in advance!
Jenkins is SSHing into the box and not receiving access to your keychain. Jenkins needs to unlock the keychain before performing the build. It looks like you already understand how to unlock your keychain via password prompt. You need to have Jenkins perform the unlock without a prompt.
Have Jenkins run the following before your build command:
security unlock-keychain -p <YourPassword> ~/Library/Keychains/login.keychain
If you'd rather not store the password in cleartext script area of your build, Jenkins offers various ways to store secrets and retrieve them as variables. Here's a decent write-up on doing that: https://support.cloudbees.com/hc/en-us/articles/203802500-Injecting-Secrets-into-Jenkins-Build-Jobs
Alternatively:
security unlock-keychain -p `cat ~/.file_with_your_password` ~/Library/Keychains/login.keychain

xcodebuild command failing on codesign but logs show incorrect profile uuid being used

I try to run this:
xcodebuild -scheme "MobileRenderStress.iOS" -destination "generic/platform=iOS" archive -archivePath /Applications/buildAgent/work/builds/MobileRenderStress-iOS.xcarchive
Which results in this:
<Many lines of irrelevant log that ends with...>
Signing Identity: "iPhone Developer: DK (RYQ82Z5555)"
Provisioning Profile: "iOSTeam Provisioning Profile: com.company.*"
(0b51596e-46c1-456a-a7bc-911858ad275a)
/usr/bin/codesign --force --sign A72FD8239B6355AE7DECC865F1A13226450F76C --entitlements /Users/builder/Library/Developer/Xcode/DerivedData/Technology-ajtzoltdytdzndgefjzzhzhiufjx/Build/Intermediates/ArchiveIntermediates/MobileRenderStress.iOS/IntermediateBuildFilesPath/MobileRenderStress.iOS.build/Debug-iphoneos/MobileRenderStress.iOS.build/MobileRenderStress.iOS.app.xcent /Users/builder/Library/Developer/Xcode/DerivedData/Technology-ajtzoltdytdzndgefjzzhzhiufjx/Build/Intermediates/ArchiveIntermediates/MobileRenderStress.iOS/InstallationBuildProductsLocation/Applications/MobileRenderStress.iOS.app
/Users/builder/Library/Developer/Xcode/DerivedData/Technology-ajtzoltdytdzndgefjzzhzhiufjx/Build/Intermediates/ArchiveIntermediates/MobileRenderStress.iOS/InstallationBuildProductsLocation/Applications/MobileRenderStress.iOS.app: User interaction is not allowed.
Command /usr/bin/codesign failed with exit code 1
** ARCHIVE FAILED **
The following build commands failed:
CodeSign /Users/builder/Library/Developer/Xcode/DerivedData/Technology-ajtzoltdytdzndgefjzzhzhiufjx/Build/Intermediates/ArchiveIntermediates/MobileRenderStress.iOS/InstallationBuildProductsLocation/Applications/MobileRenderStress.iOS.app
(1 failure)
I've been running xcodebuild commands both for building and archiving (in this example I am archiving) but I am receiving codesign errors. The confusion comes especially from the fact that the logs indicate exactly which provisioning profile ID it's trying to use (and successfully finds) but the command line for "codesign" is indicating a different ID. Even if I specify the profile in the xcodebuild command, it still ends up trying to use this different, non-existent ID in the codesign line.
Has anyone come across this before and know where that ID is even coming from? I grep'd my entire project and it's nowhere to be found. It's kinda creepy, really.
Important Notes:
When I update the provisioning profile to get the ID to change, the xcodebuild command STILL tries to use the A72 ID at the codesign line. It's really frustrating!
I do see the part of the log that indicates "User interaction is not allowed." Although this doesn't relate to the issue, do know that it's using the --force command in the line which should bypass that error and also the provisioning profile's signing keys are all fully permissive, which is the other workaround for that kind of issue.
The issue is caused by "User interaction is not allowed." this is because it needs a code signing prompt to be accepted which cannot happen from command line until the keychain has been unlocked.
security unlock-keychain -p YOUR_PASSWORD ~/Library/Keychains/login.keychain
Also you might want to do it directly in xcode and check it works on the machine.

TeamCity + Xcode 6 - Run Test action fails

I am trying to make a simple Xcode project work with TeamCity. Without running any tests I have succeeded.
I have a basic, Single View Application in Swift with one label on the screen. Both TeamCity (9.0.2) and Xcode (6.1.1) runs on the same machine (Mac mini) with an OS X (10.10.2) Server (4.0.3) installed on it. I have created a Git repository with Server and added as a remote to my sample Xcode project. After that, I've created successfully a working TeamCity project and build.
However when I try to check the Run tests checkmark the build WILL fail no matter what I do.
Configuration (dropbox image)
https://dl.dropboxusercontent.com/u/55101816/Screen%20Shot%202015-03-01%20at%2002.45.48.png
Error message (and the messages right before that)
[02:31:48][FirstTeamCityProjectTests (BUILD)] Touch
[02:31:48][Touch] Touch build/Debug-iphoneos/FirstTeamCityProjectTests.xctest
[02:31:48][Touch] cd /Library/TeamCity/buildAgent/work/55b27ad210b8fe77
[02:31:48][Touch] export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/> ontents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Server.app/Contents/ServerRoot/usr/bin:/Applications/Server.app/Contents/ServerRoot/usr/sbin"
[02:31:48][Touch] /usr/bin/touch -c /Library/TeamCity/buildAgent/work/55b27ad210b8fe77/build/Debug-iphoneos/FirstTeamCityProjectTests.xctest
[02:31:48][FirstTeamCityProjectTests (BUILD)] CodeSign
[02:31:48][CodeSign] CodeSign build/Debug-iphoneos/FirstTeamCityProjectTests.xctest
[02:31:48][CodeSign] cd /Library/TeamCity/buildAgent/work/55b27ad210b8fe77
[02:31:48][CodeSign] export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
[02:31:48][CodeSign] export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/ Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Server.app/Contents/ServerRoot/usr/bin:/Applications/Server.app/Contents/ServerRoot/usr/sbin"
[02:31:48][CodeSign] Signing Identity: "iPhone Developer: *"
[02:31:48][CodeSign] /usr/bin/codesign --force --sign * /Library/TeamCity/buildAgent/work/55b27ad210b8fe77/build/Debug-iphoneos/FirstTeamCityProjectTests.xctest
[02:31:48][Step 1/1] ** BUILD SUCCEEDED **
[02:31:48][Step 1/1] xcodebuild: error: Failed to build workspace FirstTeamCityProject with scheme FirstTeamCityProject.
[02:31:48][Step 1/1] Reason: Xcode cannot run using the selected device.
[02:31:48][Step 1/1] Process exited with code 70
[02:31:48][Step 1/1] Step Xcode Project failed
Main problem I found with this error code and CI that they were trying with ssh and there were no GUI session. Currently I have a valid GUI session with the same user it uses, so it shouldn't be a problem.
The xcodebuild command is the following.
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -workspace FirstTeamCityProject.xcodeproj/project.xcworkspace -scheme FirstTeamCityProject SYMROOT=/Library/TeamCity/buildAgent/work/55b27ad210b8fe77/build OBJROOT=/Library/TeamCity/buildAgent/work/55b27ad210b8fe77/build clean build test
What is missing here (I suppose) is one or more destinations.
I've executed the following command and it worked just fine. (Opened the Simulator, then exited with success.)
xcodebuild test -project FirstTeamCityProject.xcodeproj -scheme FirstTeamCityProject -destination 'platform=iOS Simulator,name=iPhone 6,OS=8.1'
I seem to be alone with this problem, I didn't find any other relevant hits. Looking at this tutorial: http://pivotallabs.com/ios-continuous-deployment-teamcity-hockeyapp/, my issue should not be present at all.
EDIT:
The destination is indeed missing, but I don't understand why. Moreover if I try to add it manually the build fails. (I suspect that the order of the parameters matters, but how could I add this destination elsewhere in TeamCity.)
[01:48:12][Step 1/1] Building project: /Library/TeamCity/buildAgent/work/55b27ad210b8fe77/FirstTeamCityProject.xcodeproj
[01:48:12][Step 1/1] Using Xcode 6.1.1
[01:48:12][Step 1/1] Starting: /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -workspace FirstTeamCityProject.xcodeproj/project.xcworkspace -scheme FirstTeamCityProject SYMROOT=/Library/TeamCity/buildAgent/work/55b27ad210b8fe77/build OBJROOT=/Library/TeamCity/buildAgent/work/55b27ad210b8fe77/build clean build test -destination 'platform=iOS Simulator,name=iPhone 6,OS=8.1'
[01:48:12][Step 1/1] in directory: /Library/TeamCity/buildAgent/work/55b27ad210b8fe77
[01:48:12][Step 1/1] xcodebuild: error: option 'Destination' requires at least one parameter of the form 'key=value'
I appreciate any idea you have! Thanks in advance!
in team city, when you configure the 'Xcode Project' build step,
add the destination parameter in the 'Additional command line parameters'
input box like so:
"-destination" "platform=iOS Simulator,name=iPhone 6,OS=8.4"
pay attention to the quotation marks
that solved the issue for me (I checked it on TeamCity Professional 9.1.5 (build 37377)).
Please see How to start TeamCity Build Agent on Mac OS on a user logon to make it able to run the GUI applications (also see the note for Yosemite OS).

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

error signing code of iOS App using Jenkins on MacOSX Lion

When I try to build my iOS XCode project in Jenkins I get the following error:
=== CLEAN NATIVE TARGET MyTarget OF PROJECT MyProject WITH CONFIGURATION Debug === Check dependencies [BEROR]Code Sign error: The
identity 'iPhone Developer: My Name (xxxxxxxx)' doesn't match any
valid, non-expired certificate/private key pair in your keychains
After reading some articles (like this and this) I've ensured that the login.keychain is present using:
MacMini:Keychains jenkins$ security list-keychains
"/Users/Shared/Jenkins/Home/Library/Keychains/login.keychain"
"/Library/Keychains/System.keychain"
MacMini:Keychains jenkins$
and that the SessionCreate=true is present in my /Library/LaunchDaemons/org.jenkins-ci.plist
PS. I would highlight the fact that the XCode running on my mac mini is successfully building the project,but if I run the command
/usr/bin/xcodebuild -target MyTarget -configuration Debug clean build
...I still get the same error message. Any idea?
Try to run the xcodebuild command with a selected scheme.
Edit: Instead of
/usr/bin/xcodebuild -target MyTarget -configuration Debug clean build
do this
/usr/bin/xcodebuild -scheme MyAwesomeScheme clean build
To fix this problem I had to check the "unlock keychain" option in the Jenkins job configuration (providing the password).

Resources