Symptoms
I created an IPA file in Unity Build Automation and need to upload it to a distribution service such as App Store Connect.
Cause
Build Automation does not have a way to instruct the platform to upload an IPA from the Dashboard to a distribution service.
Resolution
To upload your IPA to App Store Connect, you can use xrun altool from a post-build script such as the following:
#!/bin/bash
echo "Uploading IPA to App Store Connect..."
#Path is "/BUILD_PATH/<ORG_ID>.<PROJECT_ID>.<BUILD_TARGET_ID>/.build/last/<BUILD_TARGET_ID>/build.ipa"
path="$WORKSPACE/.build/last/$TARGET_NAME/build.ipa"
if xcrun altool --upload-app -f $path -u $ITUNES_USERNAME -p $ITUNES_PASSWORD ; then
echo "Upload IPA to App Store Connect finished with success"
else
echo "Upload IPA to App Store Connect failed"
fi
These are its variables:
ITUNES_USERNAME - Your email
ITUNES_PASSWORD - The app-generated password
TARGET_NAME - Name of the target in Build Automation
WORKSPACE - This variable is set by Build Automation
The post-build script was adapted from this forum post.
If you would like to increment the build version number automatically, you could use the following pre-export method:
using UnityEngine; using UnityEditor; using System; public class AutoIncrementVersionCodeInBuildAutomation : MonoBehaviour { #if UNITY_CLOUD_BUILD public static void PreExport(UnityEngine.CloudBuild.BuildManifestObject manifest) { string buildNumber = manifest.GetValue("buildNumber", "0"); Debug.LogWarning("Setting build number to " + buildNumber); PlayerSettings.Android.bundleVersionCode = int.Parse(buildNumber); PlayerSettings.iOS.buildNumber = buildNumber; } #endif }
Given that Apple is no longer accepting plain text user name password combinations, and only accepting generated API tokens, you can implement the following post-build script which uses the path to your API key file (.p8 file) and your issuer ID for the API key:
#!/bin/bash
echo "Uploading IPA to App Store Connect..."
# Path is "/BUILD_PATH/<ORG_ID>.<PROJECT_ID>.<BUILD_TARGET_ID>/.build/last/<BUILD_TARGET_ID>/build.ipa"
path="$WORKSPACE/.build/last/YOUR_TARGET_NAME/build.ipa"
KEY_WITH_NEWLINES=$(echo $CONNECT_API_KEY | jq '.private_key |= sub(" (?!PRIVATE|KEY)"; "\n"; "g")' -c -j)
echo $KEY_WITH_NEWLINES > ~/private_keys/YOUR_AUTH_KEY.p8
if [ ! -f ~/private_keys/YOUR_AUTH_KEY.p8 ]; then
echo "Key File not found!"
fi
# Assuming you have set API_ISSUER_ID environment variable
if [ -z "$API_ISSUER_ID" ]; then
echo "Error: API_ISSUER_ID is not set"
exit 1
fi
if xcrun altool --upload-app -type ios -f "$path" --apiKey YOUR_API_KEY --apiIssuer "$API_ISSUER_ID"; then
echo "Upload IPA to App Store Connect finished with success"
else
echo "Upload IPA to App Store Connect failed"
fi