Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate xcarchive into a specific folder from the command line

For the purposes of CI, I need to be able to generate an XCARCHIVE and an IPA file in our nightly build. The IPA is for our testers, to be signed with our ad-hoc keys, and the XCARCHIVE is to send to the client so that they can import it into Xcode and submit it to the app store when they're happy with it.

Generating the IPA is simple enough with a bit of googling, however how to generate the .XCARCHIVE file is what eludes me. The closest I've found is:

xcodebuild -scheme myscheme archive 

However, this stores the .xcarchive in some hard-to-find folder, eg:

/Users/me/Library/Developer/Xcode/Archives/2011-12-14/MyApp 14-12-11 11.42 AM.xcarchive 

Is there some way to control where the archive is put, what its name is, and how to avoid having to re-compile it? I guess the best possible outcome would be to generate the xcarchive from the DSYM and APP that are generated when you do an 'xcodebuild build' - is this possible?

like image 984
Chris Avatar asked Jan 04 '12 05:01

Chris


2 Answers

Xcode 5 now supports an -archivePath option:

xcodebuild -scheme myscheme archive -archivePath /path/to/AppName.xcarchive 

You can also now export a signed IPA from the archive you just built:

xcodebuild -exportArchive -exportFormat IPA -exportProvisioningProfile my_profile_name -archivePath /path/to/AppName.xcarchive -exportPath /path/to/AppName.ipa 
like image 169
rectalogic Avatar answered Nov 12 '22 08:11

rectalogic


Starting with Xcode 4 Preview 5 there are three environment variables that are accessible in the scheme archive's post-actions.

ARCHIVE_PATH: The path to the archive. ARCHIVE_PRODUCTS_PATH: The installation location for the archived product. ARCHIVE_DSYMS_PATH: The path to the product’s dSYM files. 

You could move/copy the archive in here. I wanted to have a little more control over the process in a CI script, so I saved a temporary file that could easily be sourced in my CI script that contained these values.

BUILD_DIR=$PROJECT_DIR/build echo "ARCHIVE_PATH=\"$ARCHIVE_PATH\"" > $BUILD_DIR/archive_paths.sh echo "ARCHIVE_PRODUCTS_PATH=\"$ARCHIVE_PRODUCTS_PATH\"" >> $BUILD_DIR/archive_paths.sh echo "ARCHIVE_DSYMS_PATH=\"$ARCHIVE_DSYMS_PATH\"" >> $BUILD_DIR/archive_paths.sh echo "INFOPLIST_PATH=\"$INFOPLIST_PATH\"" >> $BUILD_DIR/archive_paths.sh 

Then in my CI script I can run the following:

xcodebuild -alltargets -scheme [Scheme Name] -configuration [Config Name] clean archive source build/archive_paths.sh ARCHIVE_NAME=AppName-$APP_VERSION-$APP_BUILD.xcarchive cp -r "$ARCHIVE_PATH" "$BUILD_DIR/$ARCHIVE_NAME" 
like image 44
Aron Avatar answered Nov 12 '22 08:11

Aron