Question: When I archive from the command line using `xcodebuild archive`, how can I get the path to the newly created archive? I'd like to follow on with an `-exportArchive` command to create an adhoc distribution.

I know that I can define an `-archivePath`, however if I do that then Organizer doesnt know where about this archive, so that's no good.

Thoughts?

Answer: 
you can simply create a variable holding the path of the archive you want to generate. Then use the same path when you want to export

```sh
$ARCHIVE_PATH="<path_of_your_archive>" # can be something like "build/app_name.xcarchive"

# ARCHIVING

xcodebuild archive \
    -workspace "${APP_NAME}.xcworkspace" \
    -configuration $CONFIGUATION \
    -scheme $SCHEME \
    -archivePath $ARCHIVE_PATH

# EXPORTING

xcodebuild -exportArchive \
     -archivePath $ARCHIVE_PATH \
     -exportPath $OUTPUT_DIRECTORY \
     -exportOptionsPlist exportPlist.plist

```

Hope this helps you in any way!
There's `$ARCHIVE_PATH` variable that's only available in archive post-actions scripts[![enter image description here](https://i.stack.imgur.com/vz0vF.png)](https://i.stack.imgur.com/vz0vF.png)

**Edit:**
`$ARCHIVE_PATH` returns a kind of generic path that doesn't account for the date, time, or duplicate suffixes.

Use `$ARCHIVE_PRODUCTS_PATH` instead. Or actually `REAL_ARCHIVE_PATH=$(dirname ${ARCHIVE_PRODUCTS_PATH})`.