Skip to content
Latchkey

xcodebuild "Command PhaseScriptExecution failed with a nonzero exit code" in CI

A Run Script build phase (CocoaPods, SwiftLint, a "[CP]" embed, or your own shell script) returned a non-zero exit status, so Xcode aborts the build. This line is only the summary; the actual failure is printed by the script just above it.

What this error means

xcodebuild stops with "Command PhaseScriptExecution failed with a nonzero exit code". The named phase (often "[CP] Embed Pods Frameworks" or a lint step) ran a script that exited non-zero.

xcodebuild
Command PhaseScriptExecution failed with a nonzero exit code

** ARCHIVE FAILED **

Common causes

A script in the phase exited non-zero

A tool invoked by the Run Script phase (SwiftLint, a CocoaPods copy script, a custom set -e shell step) failed, and Xcode reports the phase summary rather than the underlying message.

A missing binary or PATH difference on the runner

The script calls a tool (node, swiftlint, sentry-cli) that exists locally but is not on the CI runner PATH, so it exits with command not found.

How to fix it

Read the script output above the summary

  1. Scroll up from the "PhaseScriptExecution failed" line to the script log of the named phase.
  2. Find the first real error the script printed (a missing file, a lint failure, command not found).
  3. Install the missing tool or fix the script, then re-run the build.

Surface the failing command in logs

Add set -x to a custom Run Script phase so the exact failing command and its exit code appear in CI output.

Run Script phase
set -euo pipefail
set -x
swiftlint

How to prevent it

  • Install all tools a build phase needs in a setup step before xcodebuild.
  • Use set -euxo pipefail in custom scripts so failures are visible.
  • Pin tool versions (SwiftLint, CocoaPods) so a phase does not break on an upgrade.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →