Mac hosting guide

Essential Xcodebuild CLI Flags for Faster CI

Pin the destination by UDID, set -jobs and -derivedDataPath explicitly, write a result bundle, and read PIPESTATUS[0] so a failed build never looks green. The annotated command below covers all of it.

Figment editorial teamPublished Updated Facts checked November 10, 2026

Figment Mac plans

US East. Pay before use. Hourly and daily too.

Intel Mac VM4 shared vCPUs, 4GB RAM, 80GB SSD$25per monthApple Silicon Mac VM4 shared vCPUs, 4GB RAM, 65GB SSD$39per monthDedicated M4 Pro12-core CPU, 24GB RAM, 512GB SSD$199per month

Minimum first purchase: $25 of account credit, used for your rental.

Pin the destination by UDID, set -jobs and -derivedDataPath explicitly, write a result bundle, and read ${PIPESTATUS[0]} so a failed build never looks green. Most CI scripts start with a minimal xcodebuild call and only gain flags after a painful failure. The annotated command below covers the flags that save build time and the ones that stop silent failures.

What does a good xcodebuild CI command look like?

Copy this as a starting point and remove flags that do not apply to your project.

#!/usr/bin/env bash
# xcodebuild-ci.sh - pass workspace/scheme/UDID through env; never hardcode
set -euo pipefail

xcodebuild test \
  -workspace "${XCODE_WORKSPACE:?}" \
  -scheme    "${XCODE_SCHEME:?}" \
  -configuration Debug \
  -destination "id=${SIM_UDID:?}" \
  -derivedDataPath "${DERIVED_DATA:-build/DerivedData}" \
  -resultBundlePath "build/results.xcresult" \
  -enableCodeCoverage YES \
  -quiet \
  -jobs "$(sysctl -n hw.logicalcpu)" \
  -maximum-concurrent-test-simulator-destinations 1 \
  ONLY_ACTIVE_ARCH=YES \
  | tee build/xcodebuild.log
BUILD_EXIT=${PIPESTATUS[0]}   # capture xcodebuild's exit code, not tee's
exit "${BUILD_EXIT}"

The xcodebuild option set is documented in Apple's xcodebuild technote TN2339 and in the man xcodebuild page shipped with Xcode. The underlying build system follows Apple's build settings reference.

What does each flag do?

Flag / SettingPurpose
-workspace pathUse .xcworkspace when CocoaPods or SPM packages are involved
-scheme nameExplicit scheme; xcodebuild -list prints the available names
-configuration DebugDebug for simulator tests; Release for archive and device builds
-destination "id=UDID"Pin by UDID; name lookups break after simulator runtime updates
-derivedDataPathStable directory you can cache between CI jobs
-resultBundlePathWrites a structured .xcresult for xcresulttool and dashboards
-enableCodeCoverage YESAdds a coverage report inside the result bundle
-quietSuppresses per-file progress; errors still print
-jobs NParallel compile tasks; match the runner's logical CPU count
-maximum-concurrent-test-simulator-destinations NCaps simultaneous simulator instances to control RAM
ONLY_ACTIVE_ARCH=YESCompile only the host architecture for faster simulator builds

How do I set -jobs and concurrent simulators?

Set -jobs N explicitly so the value shows in logs. It sets the number of concurrent compile tasks. The default is the logical CPU count, which suits a dedicated machine but can starve other processes on a shared runner.

-jobs "$(sysctl -n hw.logicalcpu)"   # dynamic: all CPUs on this machine
-jobs 4                               # static: safe for a 4-vCPU runner

-maximum-concurrent-test-simulator-destinations N limits simultaneous simulators when you pass multiple -destination flags. Two simulators on a 16 GB machine can swap during test runs, so keep it at 1 unless you have measured headroom.

How do I pin the simulator destination?

Resolve the UDID first and pin it. Name-based strings such as platform=iOS Simulator,name=iPhone 16,OS=18.0 fail when the runtime updates.

SIM_UDID=$(xcrun simctl list devices available -j | python3 -c '
import sys, json
runtimes = json.load(sys.stdin)["devices"]
for _, devs in runtimes.items():
    for d in devs:
        if "iPhone" in d["name"] and d["state"] != "unavailable":
            print(d["udid"]); raise SystemExit')

If the lookup returns nothing, the script fails at that step instead of producing a cryptic error from deep inside xcodebuild. For archive jobs, use -destination 'generic/platform=iOS'.

Should I use clean builds in CI?

Use incremental builds on pull requests and a clean build on main. xcodebuild clean build discards derived data and forces a full rebuild. On a cold runner that is unavoidable. On a warm runner with a persistent -derivedDataPath, omitting clean can cut compile time on large projects.

  • PRs and feature branches: omit clean and use the cache.
  • Main and release: always clean, and absorb the full cost once per merge.

Cache the derived data path keyed on Podfile.lock and Package.resolved so dependency changes invalidate it.

How do I get the real exit code?

Capture ${PIPESTATUS[0]}. Pipe xcodebuild through tee or xcpretty for readable logs, but if you read the pipe's own exit code you read the formatter's, which is usually 0 even when xcodebuild exited 65 (test failure) or 70 (internal error). A green build that was actually broken is the most common silent-failure pattern in iOS CI.

As a secondary check, parse the result bundle after the run:

xcresulttool get --path build/results.xcresult --format json \
  | python3 -c 'import sys,json; r=json.load(sys.stdin); \
    s=r.get("metrics",{}).get("testsFailedCount",{}).get("_value","0"); \
    sys.exit(1 if int(s)>0 else 0)'

Never time a failed build and call it a benchmark. Record wall time only on green runs with the same scheme, destination and derived-data state.

How do I measure what these flags save?

Pick a representative job and time three things:

  1. T_full: wall time with clean build.
  2. T_warm: wall time with warm derived data and -quiet.
  3. R: runs per working day (PRs plus main).

Monthly saved minutes are about (T_full − T_warm) × R × 21. A rented Mac on a monthly plan does not meter minutes, so the saving shows up as queue headroom, not a smaller invoice.

How does the monthly price compare with another host?

Price check (2026-11-10): CloudMac lists its base Mac mini M4 (16 GB / 256 GB) at $99.99/month, and the CloudMac home page advertises a $999/year option on the same base config, effectively $83.25/month. Over 12 months that is 12 × $99.99 = $1,199.88 monthly or $999 prepaid. Figment's Apple Silicon Mac VM is 12 × $39 = $468 a year, and the Dedicated M4 Pro 48 GB is $3,228 paid up front for 12 months. The hardware differs: CloudMac lists a whole Mac with 16 GB, the Figment VM is 4 shared vCPUs and 4GB RAM, and the Dedicated M4 Pro is a whole Mac with 48GB RAM.

Which Figment Mac plan fits this workflow?

Use the Intel VM to audit flags on older Xcode, and an Apple silicon plan for current Xcode and arm64 simulators.

  • Intel Mac VM, $25/month or $2/day: 4 shared vCPUs, 4GB RAM, macOS Sequoia. It runs Xcode 26.0 to 26.3, the range Apple lists for Sequoia, so it handles the flag audit, scheme inspection and small Intel-target test runs. It cannot run arm64-only binaries or visionOS, and Xcode 26.4 or later needs an Apple silicon plan.
  • Apple Silicon Mac VM, $39/month or $6/day: 4 shared vCPUs, 4GB RAM. It runs the arm64 simulator natively, which is what ONLY_ACTIVE_ARCH=YES compiles to on Apple silicon.
  • Dedicated M4 Pro 48 GB, $349/month, or $299/month on a 12-month term: a whole Mac if you want all cores and memory for a test-heavy job.

VM vCPUs are shared, not reserved cores, so set -jobs with that in mind and measure on your own project. Check the macOS version shown before purchase against Apple's Xcode table.


Related guides:

Which Figment Mac fits this work?

Intel Mac VM from $25 a month, Apple Silicon Mac VM from $39, or a Dedicated M4 Pro for $199. Hourly and daily plans too. You pay before use, starting with at least $25 of account credit.

Choose a Mac plan