BlogiOS
Setting up CI/CD for iOS with Xcode Cloud
The three workflows I set up for most iOS apps, plus custom scripts, secrets, and when another CI tool is the better choice.
Continuous integration is one of those things every iOS team agrees with and few set up properly. Xcode Cloud, Apple’s CI/CD service built into Xcode and App Store Connect, removes most of the excuses. It builds your app in the cloud, runs your tests, signs the build and can send it straight to TestFlight, with no build machines to maintain. This is how I usually set it up.
Start with three workflows
Each Xcode Cloud workflow has start conditions (what triggers it), actions (build, test, analyse or archive) and post-actions (like TestFlight distribution or notifications). Three workflows cover most apps:
- Pull requests. Starts on pull request changes. Builds the app and runs the test suite, so every pull request is green before anyone reviews it.
- Main branch. Starts on changes to
main. Tests, archives and sends the build to internal TestFlight testers, so the team always has the latest version on their phones. - Release. Starts on a tag like
v2.4.0. Archives the release and sends it to external TestFlight testers, ready for App Store review.
Releasing then becomes a decision, not a process: tag the commit, and the build is on its way.
Custom scripts
Xcode Cloud looks for a ci_scripts folder next to your project and runs scripts with specific names at set points: ci_post_clone.sh after the repository is cloned, ci_pre_xcodebuild.sh before the build, and ci_post_xcodebuild.sh after it. I use the first for tools and checks:
#!/bin/sh
# ci_scripts/ci_post_clone.sh
set -e
brew install swiftlint
cd "$CI_PRIMARY_REPOSITORY_PATH"
swiftlint --strict
Xcode Cloud also sets environment variables you can branch on. For example, doing something only when a workflow archives:
#!/bin/sh
# ci_scripts/ci_post_xcodebuild.sh
if [ "$CI_XCODEBUILD_ACTION" = "archive" ]; then
echo "Archived build $CI_BUILD_NUMBER"
fi
Remember to make the scripts executable with chmod +x, or they won’t run.
Keep secrets out of the repository
API keys and tokens belong in the workflow’s environment variables, marked as secret, not in the code. Scripts read them like any other variable, and they never show up in logs or in Git history.
Make tests fast
A slow pipeline gets ignored. I put unit and UI tests in a test plan and run it on several simulators in parallel, for example a small and a large iPhone, and an iPad if the app supports it. Results go to Slack or email, so a failing build gets noticed while the change is still fresh.
Xcode Cloud or another tool?
I’ve also worked with Bitrise, CircleCI and Fastlane, and each has its place. Xcode Cloud is a great fit when your app ships only on Apple platforms, you want the least setup, and you want builds to land in TestFlight with no extra steps. Something like Bitrise or CircleCI with Fastlane often fits better when:
- You also ship Android, for example with React Native.
- You need custom build machines or unusual tools.
- Your pipeline is shared with web and backend projects.
The payoff
Once it’s running, nobody archives by hand, every pull request is tested before review, and testers always have the latest build. It takes an afternoon to set up and pays for itself the first week.
Nishanth Kumar