# Automate watchOS App Builds in a CI Pipeline

Canonical: https://figment.so/blog/mac-watchos-ci-build-pipeline

Compile the iOS and Watch pair with xcodebuild, pin the Watch simulator by UDID, and keep the real exit code with PIPESTATUS[0]. An Intel Mac VM covers Xcode 26.0 to 26.3.

**Compile the iOS companion and the Watch extension with one `xcodebuild build-for-testing` run, pin the Watch simulator by UDID, run the tests, and keep `xcodebuild`'s real exit code with `PIPESTATUS[0]`.** Those last two points are where most pipelines fail: name-based destinations break when Xcode updates, and a formatter such as `xcpretty` can turn a failed test run into a green job.

## How does a paired iOS and watchOS build work in CI?

A watchOS release is usually two binaries, the iOS companion and the Watch extension, packaged in one `.ipa`. Since watchOS 7 (Xcode 12) Watch apps can ship independently, and Xcode 14 made independent the default for new projects, but most shipping apps still carry an iOS companion. When both targets share one scheme, `xcodebuild` compiles the Watch extension as a dependency of the iOS app, so you do not need a second invocation.

Compile once, then run tests from the cached artefact ([Apple's recommended CI pattern](https://developer.apple.com/documentation/xcode/running-tests-and-interpreting-results)):

```bash
xcodebuild \
  -workspace YourApp.xcworkspace \
  -scheme "YourApp" \
  -configuration Debug \
  -destination 'platform=iOS Simulator,name=iPhone 16,OS=latest' \
  build-for-testing
```

`build-for-testing` writes an `.xctestrun` bundle without running tests. A later `test-without-building` step reuses it, so you pay compile time once per commit however many destinations you fan out to.

## How do I pin the Watch simulator destination?

List what the runner has, then pick a UDID. Name-based destinations break every time Xcode or a runtime updates:

```bash
xcrun simctl list devices available | grep -E "Watch|iPhone"
```

```bash
WATCH_UDID=$(xcrun simctl list devices available -j \
  | python3 -c "
import sys, json
devs = json.load(sys.stdin)['devices']
print(next(
  d['udid']
  for runtimes in devs.values()
  for d in runtimes
  if 'Apple Watch' in d['name'] and d['state'] != 'unavailable'
))") || { echo "No watchOS simulator found"; exit 1; }
```

Pass `-destination "id=${WATCH_UDID}"` to every later `xcodebuild` call. Without a valid destination, `xcodebuild` exits before any test runs, and a careless pipe through a formatter can report that failure as success.

## How do I run the Watch extension tests headlessly?

Boot the simulator before `xcodebuild test`, because a cold boot inside the test command can exceed CI timeouts. The script below is the one to copy into your repo. The key line is `PIPESTATUS[0]`, which preserves `xcodebuild`'s exit code when stdout goes through `xcpretty`.

```bash
#!/usr/bin/env bash
# ci-watchos-test.sh
# Required: XCODE_SCHEME, XCODE_WORKSPACE
# Optional: WATCH_RESULT_BUNDLE (default build/watchos-tests.xcresult)
set -euo pipefail

SCHEME="${XCODE_SCHEME:?Set XCODE_SCHEME in CI environment}"
WORKSPACE="${XCODE_WORKSPACE:?Set XCODE_WORKSPACE in CI environment}"
RESULT_BUNDLE="${WATCH_RESULT_BUNDLE:-build/watchos-tests.xcresult}"

echo "==> Locating watchOS simulator"
WATCH_UDID=$(xcrun simctl list devices available -j \
  | python3 -c "
import sys, json
devs = json.load(sys.stdin)['devices']
print(next(
  d['udid']
  for runtimes in devs.values()
  for d in runtimes
  if 'Apple Watch' in d['name'] and d['state'] != 'unavailable'
))") || { echo "ERROR: no available watchOS simulator" >&2; exit 1; }
echo "Using simulator: ${WATCH_UDID}"

echo "==> Booting simulator"
xcrun simctl bootstatus "${WATCH_UDID}" -b

echo "==> Running WatchKit Extension tests"
set +e
xcodebuild test \
  -workspace "${WORKSPACE}" \
  -scheme "${SCHEME}" \
  -destination "id=${WATCH_UDID}" \
  -resultBundlePath "${RESULT_BUNDLE}" \
  -enableCodeCoverage YES \
  2>&1 | xcpretty --color
TEST_EXIT=${PIPESTATUS[0]}
set -e

if [ "${TEST_EXIT}" -ne 0 ]; then
  echo "ERROR: xcodebuild exited ${TEST_EXIT} - inspect ${RESULT_BUNDLE}" >&2
  exit "${TEST_EXIT}"
fi

echo "==> All tests passed"
```

This is an untested example to adapt. Run it once locally against your real scheme name before trusting the signal in CI. Without `PIPESTATUS[0]`, a successful formatter exit overwrites a failed test exit and the pipeline reports green on a broken build.

## Why does TestFlight reject my archive with a missing Watch app?

The scheme's Archive action probably excludes the Watch app target. `xcodebuild archive` then produces a `.xcarchive` with only the iOS binary, and TestFlight rejects the upload because the Watch entitlement references a bundle that is not present.

Check the scheme list, then open **Product > Scheme > Edit Scheme > Archive** in Xcode and confirm the WatchKit App target is listed with **Build** checked:

```bash
xcodebuild -list -workspace YourApp.xcworkspace
```

No flag compensates for a misconfigured scheme. Fix the `.xcscheme` file in source control and commit it.

## How do I upload the iOS and Watch IPA?

`xcodebuild -exportArchive` produces a single `.ipa`, with the Watch app embedded at `Payload/YourApp.app/Watch/WatchApp.app`, so TestFlight accepts one upload for both platforms. With Fastlane:

```bash
fastlane pilot upload \
  --ipa "build/export/YourApp.ipa" \
  --api_key_path "${API_KEY_PATH}"
```

`API_KEY_PATH` should point to a file written at runtime from a CI-managed secret, decoded into a job-scoped temp directory and never committed. See the [iOS CI secrets guide](/blog/mac-ci-env-var-secrets-ios) for a safe decode step. Update only your own CI, artifact store and firewall allowlists. There is no documented App Store Connect ingress IP range to allowlist.

## How do I pin the Xcode version on the runner?

The watchOS SDK ships inside Xcode. If a runner auto-updates Xcode, simulator runtime names change and destinations break. Pin the toolchain and log the version on every run:

```bash
sudo xcode-select --switch /Applications/Xcode_26.1.app/Contents/Developer
xcodebuild -version
```

Apple states that Intel Macs must use Xcode 26 or an earlier release ([Apple developer docs](https://developer.apple.com/documentation/apple-silicon/porting-your-macos-apps-to-apple-silicon.md)). visionOS tooling needs Apple silicon regardless, so match the host to the toolchain your project is pinned on.

## Which Figment Mac plan fits a watchOS pipeline?

| Need | Plan |
|---|---|
| Evaluate `build-for-testing` and the paired-destination script with Xcode 26.0 to 26.3 (the range Apple lists for macOS Sequoia) | [Intel Mac VM](/mac-hosting#intel-vm), $25/month or $2/day |
| Xcode 26.4 or later, Xcode 27, visionOS targets, or arm64-only dependencies | [Apple Silicon Mac VM](/mac-hosting#apple-silicon-vm), $39/month or $6/day |
| A whole Mac for a heavier or more consistent pipeline | [Dedicated M4 Pro 48 GB](/mac-hosting#dedicated-m4-pro), $349/month ($299 on a 12-month term) |

Xcode 26.4 and later need macOS Tahoe 26.2 or newer, and Xcode 27 needs Tahoe 26.6 or newer, so check the macOS version shown before purchase against Apple's Xcode table. Figment does not run your CI. You install and manage the runner, the Fastlane step and your CI secrets yourself.

## How much does a one-runner watchOS pipeline cost?

Wiring and evaluating the pipeline on an Intel Mac VM for one month costs $25. A day on the Apple Silicon VM costs $6, and a month costs $39. Over twelve months, 12 x $39 = $468 for the Apple Silicon VM and $3,228 paid up front for the Dedicated M4 Pro 48 GB (or 12 x $299 = $3,588 on a 12-month term).

For comparison, [CloudMac](https://cloudmac.org/pricing) publishes $99.99/month for a Mac mini M4/16 GB/256 GB and a $999/year option on [cloudmac.org](https://cloudmac.org/). That annual rate is $83.25/month effective (12 x $83.25 = $999). CloudMac's 256 GB row shows "Reserve now", and the 512 GB and 1 TB rows show "Fully reserved". [MacStadium](https://macstadium.com/pricing) lists M2.S at $109, M4.S at $149 and M4.M at $249, with support and a 99.99% uptime claim on that page. The hardware is not identical: Figment's Apple Silicon VM has shared vCPUs and 4GB RAM, while the CloudMac listing is a whole Mac mini with 16 GB.

*Related guides:*
- [Rotate Apple Certs in CI Without Build Downtime](/blog/mac-certificate-rotation-ci-zero-downtime)
- [Essential Xcodebuild CLI Flags for Faster CI](/blog/mac-xcodebuild-cli-flags-ci)
- [Xcode on Windows: Remote Mac Setup](/blog/mac-xcode-on-windows-remote-setup)
