Inject provisioning profile name with xcodebuild command - xcode

We are using a manual signing strategy for our iOS app. Our CI/CD pipeline is set up on Jenkins and we need to build the app using the xcodebuild command. We are using the following command to archive the app.
xcodebuild -scheme Integration -xcconfig Integration.xcconfig -configuration Debug clean archive -archivePath build/app -destination generic/platform=iOS
When we archive the app using the above command, it always fails on the below error. I would like to know how to pass the provisioning profile name with the above xcodebuild command.

I was able to find the solution. It can be done by using:
xcodebuild -scheme Integration -xcconfig Integration.xcconfig -configuration Debug clean archive -archivePath build/app -destination generic/platform=iOS PROVISIONING_PROFILE="[Your profile Unique ID here]"

Related

is there any options to change bundle identifier while generating the build using terminal

i) is it possible to change the Bundle identifier and Provisional Profiles in Codebase while generating the Archive File and IPA file.
ii) is it possible to change the Application name while generating IPA file in Command line Tools.
I am following these two syntax while generating the Archive and IPA.
xcodebuild -workspace ".workspace" -scheme "SchemeName" -archivePath "archivePath/appName.xcarchive" archive
xcodebuild -exportArchive -archivePath "archivePath/appName.xcarchive" \
-exportOptionsPlist "ecportOptionsPlist" \
-exportPath "ExportPath"

How to: `xcodebuild -xcworkspace..` with project and swift packages

I have created a xcworkspace to add my iOS.xcproj and local swift package. The workspace builds and runs great from Xcode. What would be the xcodebuild command to do in my CI?
I have been trying using the following:
xcodebuild -workspace [name].xcworkspace -scheme [scheme_name] -configuration [config] -xcconfig [path_xcconfig]
I get this in the output console:
...note: Building targets in dependency order
error: Multiple commands produce <RegisterExecutionPolicyException...
sample:
note: Target 'Firebase_FirebaseInAppMessaging_iOS' (project 'Firebase'): Touch /Users...

Archive Failed when trying "xcodebuild archive" in terminal - Doesn't include currently selected device

Systems: xcode 13, OS Monterey 12.5
Summarize the problem: My goal is to archive an iOS xcode project from command line using the xcodebuild archive command. I have my iPhone connected and xcode recognizes this device. I am able to archive this project by selecting xcode Product/Archive in the xcode IDE but for some reason when I run the xcodebuild archive command below I get the Archive Failed error that states,"Provisioning profile "iOS Team Provisioning Profile" doesn't include the currently selected device". The currently selected device stated in the error is my computer I.D. and not the iPhone I have connected. Again, this runs fine when I archive in xcode GUI so it seems my following command in terminal is incorrect.
I tried the fix in other related stackoverflow questions but they did not resolve my specific issue.
command: xcodebuild archive -target AnalyzeSourceCode.xcworkspace \ -scheme AnalyzeSourceCode \ BUILD_LIBRARY_FOR_DISTRIBUTION=YES \ SKIP_INSTALL=NO
I have tried various combinations of the command:
*Specifying workspace and destination:
xcodebuild -workspace AnalyzeSourceCode \
-scheme AnalyzeSourceCode \
-destination generic/platform=iOS build
*Also ran trace on devices to confirm my iPhone is recognized which it is because I see it in finder and in xcode GUI.
xcrun xctrace list devices
It seems that my xcodebuild command is not correct.
Solution found in Apple Forum: LINK: https://developer.apple.com/forums/thread/668952
The post originator (Namzak) had the same issue and the archive failure was due to not including the destination when running xcodebuild command in terminal when archiving the project.
The key to my solution was the destination line below:
-destination 'generic/platform=iOS'
Complete Command I Execute:
xcodebuild archive -scheme APP_NAME_HERE \
-configuration Release \
-destination 'generic/platform=iOS' \
-archivePath "APP_NAME_HERE.xcarchive"

What `xcodebuild` commands are executed when I run Product -> Archive in Xcode?

I'm trying to build an IOS app from the command line instead of through Xcode it's been an uphill struggle. My project builds fine in Xcode by going to Product -> Archive, but when I try to do what I think is the same thing in the Terminal with xcodebuild, it fails due to some missing header files.
How do I find out what actually happens when I click Archive?
Alternatively, if anyone can spot where my error is, the command I think should be working is:
xcodebuild -workspace MyApp.xcworkspace -scheme MyApp -configuration Beta -destination 'generic/platform=iOS' -archivePath <path to xcarchive file> archive
Hi I have a guess because I could not find the actual documentation. I have a small script that works for deployment directly on the App Store using my private keys.
I'm sharing with you if it can helps, I'm asking you to accept the answer.
#clean and build
xcodebuild -workspace ./my-app.xcworkspace/ -scheme my-app -sdk iphonesimulator12.0 clean # analyze
xcodebuild -workspace ./my-app.xcworkspace/ -scheme my-app -destination generic/platform=iOS build
#archive
xcodebuild -workspace ./my-app.xcworkspace/ -scheme my-app -sdk iphoneos -configuration AppStoreDistribution archive -archivePath $PWD/build/my-app.xcarchive
# create build ipa
xcodebuild -exportArchive -archivePath $PWD/build/my-app.xcarchive -exportOptionsPlist exportOptions.plist -exportPath $PWD/build
# /Applications/Xcode.app/Contents/Applications/Application\ Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Support/altool
# upload app for testflight
export USERNAME=myusername
export PASSWORD=mypassword
# password is generated at appleid.apple.com
cd build
altool --upload-app -f "my-app.ipa" -u $USERNAME -p $PASSWORD
References
How do I determine the target architecture of static library (.a) on Mac OS X?
https://github.com/fastlane/fastlane/issues/13401
https://medium.com/xcblog/xcodebuild-deploy-ios-app-from-command-line-c6defff0d8b8
You mentioned that your app fails because of header files, I'm suggesting that you check this out because it can be a pain in the ... sometimes. By the way my app has some native headers too.

xcodebuild fails through Jenkins

We have been doing CI builds through Jenkins. I did not set up Jenkins so I can't answer questions about how its set up.
We are adding a WatchKit extension. We are following these steps https://developer.apple.com/library/mac/qa/qa1814/_index.html to switch from specifing the provisioning profile to switching to automatic.
The build command fails through Jenkins, but if I run the command from the command line, it works. I think both are using the same user. The distribution certificate is in the login keychain and the system keychain.
Our command is
xcodebuild -configuration Release -target "mobile" -sdk "iphoneos8.3" -scheme "mobile" clean archive
The error we get is like this for each extension and application:
Code Sign error: No code signing identities found: No valid signing identities (i.e. certificate and private key pair) matching the team ID “XXXXXXXXXX” were found.
CodeSign error: code signing is required for product type 'App Extension' in SDK 'iOS 8.3'
Any advice how to fix or troubleshoot this error?
Try moving the certificates you required in your Keychain. Move them from Login to System
Try adding Jenkins profile management plugin & adding prov and then compile using XCBuild.
When I execute the following command via Execute Shell, I am able to run xcodebuild:
security unlock-keychain -p ${OSPASSWORD} ~/Library/Keychains/login.keychain-db && xcodebuild -scheme ${XCODE_SCHEME} -sdk ${XCODE_SDK} -archivePath \"build\" -configuration Release archive
Hope it helps.

Resources