Fix Xcode Exit Code 65 in GitHub Actions iOS Builds
Exit code 65 is xcodebuild's generic failure status. Find the real error in the log, then fix Xcode selection, code signing, or simulator destinations.
At a glance
- Last reviewed
- Versions referenced
actions/checkout@v7actions/upload-artifact@v7maxim-lobanov/setup-xcode@v1- Reading time
- 3 min read
Code samples are not run in a live repository. See our editorial standards.
On this page
Exit code 65 is the generic status xcodebuild returns when a build or test action fails, so the cause is in the log lines above it, not in the code itself. Capture the log, find the first error: line, then check the three usual causes: the wrong Xcode version, broken code signing, and an unresolvable simulator destination.
Find the Real Error First
Pipe xcodebuild through tee with set -o pipefail, so the step fails with the xcodebuild status and you keep a full log to search.
name: Build iOS App
on:
push:
branches: [main]
jobs:
build:
runs-on: macos-14
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Build iOS App
run: |
set -o pipefail
xcodebuild \
-workspace MyApp.xcworkspace \
-scheme MyApp \
-configuration Debug \
-destination 'generic/platform=iOS' \
clean build | tee xcodebuild.log
- name: Show build errors
if: failure()
run: grep -E 'error:|BUILD FAILED' xcodebuild.log || true
- name: Upload raw log
if: failure()
uses: actions/upload-artifact@v7
with:
name: xcodebuild-raw-log
path: xcodebuild.log
Without pipefail, the pipeline returns the exit status of tee, which hides the failure. The actionable lines usually sit above the final ** BUILD FAILED ** block, and with parallel targets they can be scattered.
Search for these markers:
error:for compiler errors, missing modules and syntax problems.fatal error:for missing headers or broken module dependencies.Testing failed:forxcodebuild testfailures. Tests that fail also produce exit code 65 even when everything compiled.Code Signing Errororerror: Provisioning profilefor signing problems.
To verify, open the Show build errors step on the failed run. It should print the first real compiler, signing or test error.
Common Signatures
A missing module means a dependency was not resolved or the framework target does not build for the selected platform:
MyApp/AppDelegate.swift:10:8: error: no such module 'SharedFramework'
Run your dependency step (for example pod install or Swift Package resolution) before the build, and build the .xcworkspace when you use CocoaPods.
A linker failure points to missing binaries, such as pods or static libraries that are not linked into the target:
clang: error: linker command failed with exit code 1
Select the Xcode Version
Pin the Xcode version when your project needs a toolchain other than the runner’s default. GitHub-hosted macOS runners have several Xcode versions installed under /Applications, and the default may be older or newer than what your project expects.
- name: Select Xcode version
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '15.4'
- name: Verify Xcode version
run: xcodebuild -version
This fix applies only if the log shows SDK, Swift version or missing-platform errors. It does not help with signing or test failures.
Without a third-party action, switch the developer directory yourself:
- name: Select Xcode manually
run: sudo xcode-select -s /Applications/Xcode_15.4.app/Contents/Developer
Confirm the path exists on your runner image first, since the installed versions change between images. To verify, the xcodebuild -version step must print the version you selected.
Fix Code Signing
Import the certificate into a temporary keychain and install the provisioning profile before building. A headless runner has no login keychain, so xcodebuild cannot find a signing identity unless you create one.
Export the .p12 certificate and the .mobileprovision profile, then encode them on your Mac:
base64 -i BUILD_CERTIFICATE.p12 | pbcopy
base64 -i PROVISIONING_PROFILE.mobileprovision | pbcopy
Under Settings > Secrets and variables > Actions, create these repository secrets:
BUILD_CERTIFICATE_BASE64: the Base64 string of the.p12file.P12_PASSWORD: the password you set when exporting the.p12.BUILD_PROVISION_PROFILE_BASE64: the Base64 string of the profile.KEYCHAIN_PASSWORD: any random string for the temporary keychain.
- name: Install Apple certificate and provisioning profile
env:
BUILD_CERTIFICATE_BASE64: ${{ secrets.BUILD_CERTIFICATE_BASE64 }}
P12_PASSWORD: ${{ secrets.P12_PASSWORD }}
BUILD_PROVISION_PROFILE_BASE64: ${{ secrets.BUILD_PROVISION_PROFILE_BASE64 }}
KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }}
run: |
CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12
PP_PATH=$RUNNER_TEMP/build_pp.mobileprovision
KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db
echo -n "$BUILD_CERTIFICATE_BASE64" | base64 --decode > "$CERTIFICATE_PATH"
echo -n "$BUILD_PROVISION_PROFILE_BASE64" | base64 --decode > "$PP_PATH"
security create-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
security set-keychain-settings -lut 21600 "$KEYCHAIN_PATH"
security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
security import "$CERTIFICATE_PATH" -P "$P12_PASSWORD" -A -t cert -f pkcs12 -k "$KEYCHAIN_PATH"
security set-key-partition-list -S apple-tool:,apple: -k "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
security list-keychain -d user -s "$KEYCHAIN_PATH"
mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles
cp "$PP_PATH" ~/Library/MobileDevice/Provisioning\ Profiles/
Passing secrets through env keeps them out of the script text and out of the workflow’s expanded command. set-key-partition-list lets codesign use the private key without a GUI prompt, which would otherwise hang a non-interactive session. -lut 21600 keeps the keychain from locking for six hours.
Provisioning errors in the log usually mean the profile type does not match the configuration. For example, a development profile combined with a Release or distribution build fails with an error naming the entitlement mismatch. Match the profile, certificate, bundle identifier and team ID to the configuration you build.
Remove the keychain after the job. This matters most on self-hosted runners, where state persists between jobs:
- name: Clean up keychain and profile
if: always()
run: |
security delete-keychain "$RUNNER_TEMP/app-signing.keychain-db" || true
rm -f ~/Library/MobileDevice/Provisioning\ Profiles/build_pp.mobileprovision
To verify, run security find-identity -v -p codesigning "$RUNNER_TEMP/app-signing.keychain-db" as an extra step. It should list at least one valid identity.
Fix the Simulator Destination
Use a device that exists on the runner image. If -destination names a device or OS that is not installed, xcodebuild cannot resolve it and fails.
- name: Run unit tests
run: |
set -o pipefail
xcodebuild test \
-project MyApp.xcodeproj \
-scheme MyApp \
-destination 'platform=iOS Simulator,name=iPhone 15,OS=latest'
List what the selected Xcode actually provides, and pick a name from that output:
- name: List simulators
run: |
xcrun simctl list runtimes
xcrun simctl list devices available
If several runtimes contain a device with the same name, pin an exact OS version (for example OS=17.5) or select the device by UDID:
- name: Run tests by simulator UDID
run: |
set -o pipefail
DEVICE_ID=$(xcrun simctl list devices available -j | jq -r '
[.devices[][] | select(.name == "iPhone 15")] | first | .udid // empty
')
if [ -z "$DEVICE_ID" ]; then
echo "No available iPhone 15 simulator found"
exit 1
fi
xcodebuild test \
-project MyApp.xcodeproj \
-scheme MyApp \
-destination "platform=iOS Simulator,id=$DEVICE_ID"
The jq filter flattens the per-runtime arrays that simctl returns before selecting by name. To verify, the listing step shows the device you target, and the test log begins compiling instead of failing at destination resolution.
Confirm the Fix
Re-run the workflow and check three things:
xcodebuild -versionprints the Xcode version you pinned.- The Show build errors step is skipped, because the build step succeeded.
- The
xcodebuildstep ends with** BUILD SUCCEEDED **(or** TEST SUCCEEDED **for tests) and the job is green.
Spotted an error? Report it on our Contact page and see our editorial standards for how we correct articles.