Running the iOS Simulator on CI/CD Pipelines
- Select the iOS simulator
- Run the iOS simulator
- Check the iOS simulator
- Install an application in iOS simulator
- Run iOS simulator on CI/CD pipelines
Select the iOS simulator
The command below will store the UDID in the current environment variables to be used later.
UDID=$(xcrun simctl list devices | grep "$IOS_SIMULATOR (" | grep -oE "[0-9A-F\-]{36}" | head -n 1)
Replace
$IOS_SIMULATORwith the desired device such as iPhone SE (3rd generation), iPhone 15, iPhone 16 Pro etc.
You can check the available devices using the command
xcrun simctl list devices.
Replace
head -n 1withsed -n '2p'if, for example, you want the second device returned by thegrepcommand (because the same device can have multiple iOS versions available).
Run the iOS simulator
xcrun simctl boot "$UDID"
open -a Simulator
Check the iOS simulator
Before using the simulator, it's better to first check if it booted successfully.
xcrun simctl bootstatus "$UDID" -b
Install an application in iOS simulator
First, build your application for a simulator as the target in Xcode, since you can't install an .ipa file on the simulator.
xcodebuild -workspace "${APP_WORKSPACE}.xcworkspace" \
-scheme "${APP_SCHEME}" \
-sdk iphonesimulator \
-configuration Release \
-derivedDataPath build
Then, install the application in the iOS simulator, ensuring that $APP_BUILD_PATH points to an .app directory previously built for a simulator as the target in Xcode.
xcrun simctl install booted "$APP_BUILD_PATH"
Run iOS simulator on CI/CD pipelines
Below is the complete solution that will work on macOS agents in CI/CD environments.
# Select the iOS simulator
UDID=$(xcrun simctl list devices | grep "$IOS_SIMULATOR (" | grep -oE "[0-9A-F\-]{36}" | head -n 1)
# Run the iOS simulator
xcrun simctl boot "$UDID"
open -a Simulator
# Check the iOS simulator
xcrun simctl bootstatus "$UDID" -b
# Install an application in iOS simulator
xcrun simctl install booted "$APP_BUILD_PATH"
The commands above were tested in Azure Pipelines running on macOS-14 agent.