xcodebuild archive unknown error -1=ffffffffffffffff

I'm trying to build an ipa for an iPhone app from the command line using Jenkins, but whenever I try:


xcodebuild archive \
-project path/to/Sample.xcodeproj \
-scheme Release \
-derivedDataPath path/to/DerivedData \
-sdk iphoneos \
-configuration Release \
-archivePath path/to/Sample.xcarchive \
-xcconfig config.xcconfig \


All I get is this useless error message saying:


/usr/bin/codesign --force --sign E6E504CD3E00A1C5F9C4BE0C446171009A79640C --entitlements path/to/DerivedData/Build/Intermediates.noindex/ArchiveIntermediates/Release/IntermediateBuildFilesPath/Sample.build/Release-iphoneos/Release.build/Sample.app.xcent --timestamp=none path/to/DerivedData/Build/Intermediates.noindex/ArchiveIntermediates/Release/InstallationBuildProductsLocation/Applications/Sample.app
path/to/DerivedData/Build/Intermediates.noindex/ArchiveIntermediates/Release/InstallationBuildProductsLocation/Applications/Sample.app: unknown error -1=ffffffffffffffff
Command /usr/bin/codesign failed with exit code 1


I don't understand why Apple won't make an effort to improve the messaging behind these cryptic obscure errors. Is this documented anywhere? You'd think that with so many forced Xcode and Mac OS updates during the year, at least some care would go into this.


I found a post in StackOverflow on the subject and following one of the recommendations there tried:


security unlock-keychain -p MY_PASS ~/Library/Keychains/login.keychain
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k MY_PASS ~/Library/Keychains/login.keychain
security set-keychain-settings ~/Library/Keychains/login.keychain


This somehow fixed the issue, but broke my Git integration and the Mac ***** was thereafter unable to clone repositories, until I rebooted it.

The worst part is that this used to work without issues, and then one day it simply stopped working for no good reason.


Can anyone please help me understand what's happening here? I'm using Xcode 9.1.