Put scheme, workspace and export_method in fastlane/Gymfile, call match with readonly: is_ci, run gym, then assert that the IPA path from lane_context exists. The same Gymfile and lane run unchanged on GitHub Actions and Buildkite.
Raw xcodebuild -exportArchive commands spread flags across pipeline YAML, hide export options in a plist, and bury errors in logs thousands of lines long. Fastlane's gym action (an alias for build_app) wraps the archive-and-export sequence in one readable config. This guide gives a portable Gymfile, a lane that asserts the IPA path, and the match wiring for signing.
Why use gym instead of raw xcodebuild?
Gym runs xcodebuild archive then xcodebuild -exportArchive in one pass. It applies xcpretty formatting so errors are readable, and it writes the raw xcodebuild log under ~/Library/Logs/gym/ for post-mortems, both confirmed in the gym docs. A Gymfile at the project root keeps pipeline YAML short, so no reviewer needs to parse a 20-flag xcodebuild invocation.
Install fastlane once per runner. Bundle it with your project so CI uses a pinned version:
# Project-local, reproducible
bundle init
bundle add fastlane
bundle exec fastlane --version
Which Gymfile fields do I need?
Usually these. The Gymfile is a Ruby DSL file at fastlane/Gymfile. Every field has a default, so specify only what differs:
# fastlane/Gymfile
# Required: which scheme to build. Use the exact scheme from your project.
scheme(ENV.fetch("APP_SCHEME"))
# Use workspace if you have CocoaPods or multi-project setups
workspace(ENV.fetch("APP_WORKSPACE"))
# Build configuration (default: Release)
configuration("Release")
# Export method: "app-store", "ad-hoc", "development", "enterprise"
export_method("app-store")
# Where to write the IPA
output_directory(ENV["RUNNER_TEMP"] || "./build")
# Explicit IPA filename (default: scheme name)
output_name(ENV.fetch("APP_SCHEME"))
# Extra xcodebuild flags passed verbatim
xcargs("ONLY_ACTIVE_ARCH=NO")
# Keep xcpretty enabled for readable output
xcpretty_args("--color --simple")
Driving scheme and workspace from environment variables keeps the Gymfile reusable across projects. Use values that match your own Xcode project. xcargs appends KEY=VALUE build settings directly to xcodebuild, so use it when there is no dedicated Gymfile key.
How do I assert that the IPA was produced?
Check SharedValues::IPA_OUTPUT_PATH in the lane. The lane orchestrates signing (match), the build (gym), and an explicit check that the IPA landed where downstream steps expect it.
# fastlane/Fastfile
default_platform(:ios)
platform :ios do
desc "Build a signed App Store IPA and assert the output file exists"
lane :build_release do
match(
type: "app-store",
readonly: is_ci,
app_identifier: ENV.fetch("APP_BUNDLE_ID")
)
gym
ipa_path = lane_context[SharedValues::IPA_OUTPUT_PATH]
UI.user_error!("IPA_OUTPUT_PATH not set by gym") if ipa_path.nil?
UI.user_error!("IPA not found at #{ipa_path}") unless File.exist?(ipa_path)
UI.success("IPA produced at: #{ipa_path}")
end
end
is_ci returns true when the CI environment variable is set, which GitHub Actions, Buildkite, and most CI platforms do automatically. Readonly match fetches existing certificates and profiles without generating new ones, which is the right default in CI per the match docs.
The assertion catches the case where gym exits zero but downstream steps (TestFlight upload, artifact upload) look at the wrong path. SharedValues::IPA_OUTPUT_PATH is the documented lane-context key for the generated IPA.
How do I use match for signing in CI?
Store the passphrase as MATCH_PASSWORD and the repository URL in a Matchfile. Match stores encrypted certificates and provisioning profiles in a Git repository, S3, or Google Cloud Storage. For Git, the documented MATCH_PASSWORD environment variable lets the decrypt step run without a prompt:
# fastlane/Matchfile
git_url("git@github.com:your-org/certificates.git")
storage_mode("git")
type("appstore")
In CI, provide only the secret:
MATCH_PASSWORD=<your-match-passphrase>
Keep the passphrase in your CI secret store (GitHub Actions encrypted secrets, Buildkite agent-level secrets), not in the Fastfile or any file in source control. Match installs the profile and sets PROVISIONING_PROFILE_SPECIFIER, which gym picks up automatically.
Signing material moving to a new runner should transfer as an encrypted .p12 for the signing identity (certificate plus private key) and the .mobileprovision files on disk. Provisioning profiles are files, not Keychain items, so copy them from ~/Library/MobileDevice/Provisioning Profiles/ rather than exporting them from Keychain. For a full match setup, see Fastlane Match for CI Code Signing.
How do I run the same Gymfile on GitHub Actions and Buildkite?
Wire the environment and the artifact upload. The Gymfile has no CI-platform-specific syntax, so only the output directory and secrets differ.
GitHub Actions:
# .github/workflows/build.yml
jobs:
build:
runs-on: [self-hosted, macOS]
env:
RUNNER_TEMP: ${{ runner.temp }}
APP_SCHEME: MyApp
APP_WORKSPACE: MyApp.xcworkspace
APP_BUNDLE_ID: com.example.MyApp
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
steps:
- uses: actions/checkout@v4
- run: bundle install
- run: bundle exec fastlane build_release
- uses: actions/upload-artifact@v4
with:
name: ipa-${{ github.sha }}
path: ${{ runner.temp }}/MyApp.ipa
Buildkite:
# .buildkite/pipeline.yml
steps:
- label: "Build release IPA"
command: "bundle install && bundle exec fastlane build_release"
env:
RUNNER_TEMP: "build"
APP_SCHEME: "MyApp"
APP_WORKSPACE: "MyApp.xcworkspace"
APP_BUNDLE_ID: "com.example.MyApp"
agents:
queue: "mac-runners"
artifact_paths: "build/MyApp.ipa"
How do I debug a gym failure?
Read the raw xcodebuild log that gym wrote, not the xcpretty summary:
ls ~/Library/Logs/gym/
grep -nE "error:|note: Using|CodeSign" ~/Library/Logs/gym/MyApp-MyApp.log | head -40
| Symptom | Where to look in the raw log |
|---|---|
| Signing identity not found | error: near CodeSign lines |
| Provisioning profile mismatch | embedded.mobileprovision lines |
| Archive missing device slice | ONLY_ACTIVE_ARCH or arm64 lines |
| Missing scheme | does not contain a scheme named |
| xcpretty hid the error | re-run with gym(disable_xcpretty: true) |
For a one-off diagnostic run, pass verbose through to xcodebuild from the lane:
gym(verbose: true)
Leave it off by default, because the output is large and slows log ingestion.
Which plan matches your gym builds per day?
Match the plan to your Xcode version and concurrency:
- Current Xcode, one app, a few builds a day: the Apple Silicon Mac VM, $39 a month ($468 for 12 months, 12 × $39), or $6 a day for a few release days.
- Parallel PR builds or several apps at once: the Dedicated M4 Pro 48 GB, $349 a month ($3,228 paid up front for 12 months), a whole Mac with an M4 Pro chip, 48GB RAM and a 512GB SSD.
- Legacy target on Xcode 26.3 or earlier: the Intel Mac VM, $25 a month, on macOS Sequoia. It cannot run arm64-only binaries or visionOS. Confirm your Xcode and macOS pair in the Xcode release notes.
You install and run the CI runner and Fastlane yourself. For comparison, CloudMac publishes a $99.99/month M4/16 GB/256 GB offer and a $999/year annual on cloudmac.org/pricing and cloudmac.org (effective $83.25/month if you prepay the year, with the 256 GB tier marked Reserve now and larger tiers Fully reserved at the time of writing). That is a whole 16 GB Mac, while Figment's VM is a shared 8GB VM, so compare hardware as well as price.
Related guides: