Perché usare un runner CircleCI self-hosted su Mac?
CircleCI offre ambienti di esecuzione macOS basati sul cloud, ma comportano costi e limitazioni significativi. CircleCI fattura i job macOS in crediti: la resource class m4pro.medium consuma 200 crediti al minuto (circa $0,12) e m4pro.large 400 (circa $0,24), a ottobre 2026. Per i team che eseguono build iOS frequenti, questo può rapidamente arrivare a $300-$500 al mese o più.
Un runner self-hosted su un Mac Mini M4 dedicato di MyRemoteMac elimina del tutto la fatturazione al minuto. Ottieni una macchina Apple Silicon dedicata con archiviazione persistente, cache calde e accesso root completo per una tariffa mensile fissa a partire da $85/mese. Ecco un confronto dettagliato:
| Caratteristica | MyRemoteMac self-hosted | CircleCI Cloud macOS |
|---|---|---|
| Modello di costo | $85/mese fisso (minuti illimitati) | 200 crediti/min su m4pro.medium (~$0,12/min) |
| Architettura | Mac Apple M4 fisico, assegnato 1:1 | Macchina virtuale M4 Pro (6 vCPU, 28 GB) |
| Velocità di build | ~5 min (stesso progetto) | ~14 min (progetto iOS medio) |
| Persistenza della cache | Persistente su disco (istantanea) | Effimera (da ripristinare a ogni job) |
| Tempo di attesa in coda | 0s (hardware dedicato) | 30s - 5min (varia in base al piano) |
| Privacy / controllo dei dati | Macchina dedicata, controllo totale | Infrastruttura condivisa |
| Software personalizzato | Accesso root completo, qualsiasi software | Solo immagine preinstallata |
Prezzi My Remote Mac in USD, tasse escluse.
Vantaggio chiave: con un runner self-hosted persistente, DerivedData, le cache di Swift Package Manager e CocoaPods vengono conservati tra una build e l'altra. Questo da solo può ridurre i tempi di build del 50-70% rispetto agli ambienti macOS cloud effimeri di CircleCI, che ripartono da zero ogni volta. Combinato con le prestazioni single-thread superiori del chip M4, le tue build iOS saranno notevolmente più veloci.
Prerequisiti
Prima di iniziare, assicurati di avere quanto segue:
- Un build server Mac mini M4 dedicato di My Remote Mac (da $85/mese, USD, tasse escluse)
- Un'organizzazione CircleCI di cui sei amministratore (i runner self-hosted sono disponibili in tutti i piani, incluso Free, che consente 5 task self-hosted simultanei a ottobre 2026)
- Accesso SSH al tuo Mac Mini (fornito con il tuo abbonamento MyRemoteMac)
- Un account Apple Developer (per il code signing e i provisioning profile)
- Familiarità di base con YAML, la configurazione di CircleCI e i comandi da terminale
Passo 1: Verifica Xcode e installa le dipendenze
Innanzitutto, collegati al tuo Mac Mini M4 via SSH con le credenziali che hai ricevuto quando hai configurato il tuo server MyRemoteMac. Xcode, i suoi Command Line Tools e Homebrew sono già installati, quindi ti basta aggiungere gli strumenti di build richiesti dalla tua pipeline iOS prima di configurare il runner CircleCI.
Collegati via SSH
# Connect to your Mac mini M4
ssh admin@your-server-ip
# Verify you're on Apple Silicon
uname -m
# Expected output: arm64
# Show the macOS version
sw_vers
Verifica Homebrew e gli Xcode Command Line Tools
# Homebrew comes preinstalled: put it on your PATH for your zsh sessions
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
brew --version
# Add Homebrew to PATH for CircleCI job steps
# (CircleCI runs macOS steps in a bash login shell)
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile
# Xcode and its Command Line Tools come preinstalled
xcode-select -p
# /Applications/Xcode.app/Contents/Developer
# Accept the Xcode license if it asks
sudo xcodebuild -license accept
Verifica Xcode e aggiungi altre versioni
Per le build iOS ti serve l'applicazione Xcode completa. Dal 28 aprile 2026 App Store Connect accetta solo build create con Xcode 26 o successivo, e la versione di Xcode preinstallata sul tuo server rispetta questa regola. Installa un'altra versione in parallelo con xcodes solo se il tuo progetto ne ha bisogno:
# Check the preinstalled Xcode
xcodebuild -version
# Xcode 27.2
# Optional: add other Xcode releases side by side with the xcodes CLI
brew install xcodes
xcodes list
# Install an older release next to the preinstalled one (asks for your Apple Account)
xcodes install 26.6
# Show the installed versions and their paths
xcodes installed
# e.g. /Applications/Xcode.app and /Applications/Xcode-26.6.0.app
# Set the default Xcode (sudo asks for your password)
# preinstalled Xcode; for another version, use the path from xcodes installed
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
Installa i simulatori iOS e gli strumenti di build
# Install the current iOS simulator runtime
xcodebuild -downloadPlatform iOS
# Verify simulator availability
xcrun simctl list runtimes
# Install additional build tools
brew install xcbeautify fastlane swiftlint
Passo 2: installa il runner agent di CircleCI
Il machine runner 3 di CircleCI collega il tuo Mac mini a CircleCI: riceve i job e li esegue direttamente sul tuo host macOS. Su macOS, CircleCI consiglia di installarlo con il suo pacchetto Homebrew. Questo è diverso dal container runner (che funziona solo su Linux).
Scegli l'utente che esegue i tuoi job
Il machine runner 3 esegue ogni job come l'utente macOS che lo avvia, con Homebrew, portachiavi e Xcode di quell'utente. Installalo e avvialo con il tuo utente amministratore, quello a cui appartiene Homebrew, non come root: Homebrew si rifiuta di funzionare come root.
# Run the steps below as the user that will run CI jobs, not with sudo
whoami
# Homebrew must work for this user (prints /opt/homebrew)
brew --prefix
Installa il machine runner 3 con Homebrew
# Add CircleCI's Homebrew tap and install machine runner 3
brew tap circleci-public/circleci
brew install circleci-runner
# Check that macOS accepts the binary notarized by CircleCI
spctl -a -vvv -t install "$(brew --prefix)/bin/circleci-runner"
# Expected: accepted, source=Notarized Developer ID,
# origin=Developer ID Application: Circle Internet Services Inc.
# Remove the quarantine attribute (asks for your macOS password)
sudo xattr -r -d com.apple.quarantine "$(brew --prefix)/bin/circleci-runner"
Configura il runner agent
Il pacchetto Homebrew crea il file di configurazione. Ti servirà il tuo token di autenticazione del runner dall'app web di CircleCI (trattato nel Passaggio 3). Per ora, imposta il nome del runner e lascia un segnaposto per il token:
# Open the configuration file created by the Homebrew package
nano "$HOME/Library/Preferences/com.circleci.runner/config.yaml"
# Contents (the token comes in Step 3):
runner:
name: "mac-mini-m4-runner"
working_directory: "/Users/$USER/Library/com.circleci.runner/workdir"
cleanup_working_directory: true
api:
auth_token: "YOUR_RUNNER_TOKEN_HERE"
# The file will hold a secret: make it readable by you only
chmod 600 "$HOME/Library/Preferences/com.circleci.runner/config.yaml"
Prepara il servizio launchd per un Mac senza interfaccia grafica
Il pacchetto Homebrew installa anche un agent launchd, com.circleci.runner. Un agent di norma si avvia quando il tuo utente accede; su un Mac che raggiungi solo via SSH, la configurazione headless di CircleCI lo sposta in /Library/LaunchAgents perché venga caricato dopo un riavvio. Avvialo nel Passaggio 3, quando il token è al suo posto:
# The launchd agent installed by the Homebrew package
ls ~/Library/LaunchAgents/com.circleci.runner.plist
# Headless Mac reached over SSH only: move it to the per-user agents
# folder so it loads after a reboot (CircleCI's headless setup)
sudo mv ~/Library/LaunchAgents/com.circleci.runner.plist /Library/LaunchAgents/
Importante: il runner non si connetterà finché config.yaml non contiene un token di autenticazione valido. Generalo nel Passaggio 3, aggiungilo al file, poi avvia il servizio.
Passo 3: configura il runner nella dashboard di CircleCI
Ora devi registrare il tuo runner nell'interfaccia web di CircleCI e generare un token di autenticazione. Questo collega il tuo Mac Mini alla tua organizzazione CircleCI.
Crea una resource class
In CircleCI, i runner self-hosted sono organizzati per resource class. Una resource class è un'etichetta che mappa il tuo .circleci/config.yml a un insieme specifico di runner.
- Nell'app web di CircleCI, apri Runners nella barra laterale (devi essere amministratore dell'organizzazione)
- Clicca su "Create Resource Class"
- Imposta il Namespace sul nome della tua organizzazione (ad es.
your-org) - Imposta il nome della Resource Class su qualcosa di descrittivo (ad es.
mac-runner) - Questo crea un identificatore di resource class:
your-org/mac-runner
Genera un token di autenticazione del runner
- Clicca su "Save and continue": CircleCI crea la resource class e mostra il suo token di autenticazione
- Copia subito il token e conservalo al sicuro: viene mostrato una sola volta
- Perso? Creane uno nuovo con la CLI di CircleCI:
circleci runner token create your-org/mac-runner mac-mini-m4
Aggiungi il token e avvia il runner
# SSH back into your Mac mini
ssh admin@your-server-ip
# Replace YOUR_RUNNER_TOKEN_HERE with the resource class token
nano "$HOME/Library/Preferences/com.circleci.runner/config.yaml"
# Start the service. Headless Mac (plist moved to /Library/LaunchAgents):
launchctl bootstrap user/$(id -u) /Library/LaunchAgents/com.circleci.runner.plist
launchctl enable user/$(id -u)/com.circleci.runner
launchctl kickstart -k user/$(id -u)/com.circleci.runner
# Or, from a desktop session (VNC), with the plist left in ~/Library/LaunchAgents:
# launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.circleci.runner.plist
# launchctl enable gui/$(id -u)/com.circleci.runner
# launchctl kickstart -k gui/$(id -u)/com.circleci.runner
# Verify the service, then read the runner log
launchctl print user/$(id -u)/com.circleci.runner
tail -20 "$HOME/Library/Logs/com.circleci.runner/runner.log"
Una volta connesso, il runner compare sotto Runners nell'app web di CircleCI, e anche circleci runner instance list your-org/mac-runner lo mostra. Se non appare entro 60 secondi, controlla il file di log per eventuali messaggi di errore.
Usare la CLI di CircleCI (alternativa)
Puoi anche gestire i runner tramite la CLI di CircleCI:
# Install the CircleCI CLI
brew install circleci
# Authenticate with CircleCI
circleci setup
# Create the namespace (once per organization)
circleci namespace create your-org --org-id YOUR_ORGANIZATION_ID
# Create the resource class and print its token
circleci runner resource-class create your-org/mac-runner \
"Mac mini M4 runner" --generate-token
# List the runners connected to this resource class
circleci runner instance list your-org/mac-runner
Passo 4: crea il tuo .circleci/config.yml per le build iOS
Crea un file .circleci/config.yml nella radice del tuo repository. La differenza fondamentale rispetto a una configurazione CircleCI standard è l'uso di machine: true con la tua resource_class personalizzata per puntare al tuo runner self-hosted.
version: 2.1
jobs:
build-and-test:
machine: true
resource_class: your-org/mac-runner
environment:
# Xcode for this job, without sudo
# (preinstalled Xcode; for another version, use the path from `xcodes installed`)
DEVELOPER_DIR: "/Applications/Xcode.app/Contents/Developer"
SCHEME: "MyApp"
# Any device listed by: xcrun simctl list devices available
DESTINATION: "platform=iOS Simulator,name=iPhone 17,OS=latest"
steps:
- checkout
- run:
name: Show the Xcode version
command: xcodebuild -version
# Caches live in $HOME, outside the job's working directory,
# so they survive cleanup_working_directory between jobs
- run:
name: Resolve Swift Package Dependencies
command: |
xcodebuild -resolvePackageDependencies \
-scheme "$SCHEME" \
-clonedSourcePackagesDirPath "$HOME/spm-cache"
- run:
name: Build the app
command: |
xcodebuild build \
-scheme "$SCHEME" \
-destination "generic/platform=iOS Simulator" \
-clonedSourcePackagesDirPath "$HOME/spm-cache" \
-derivedDataPath "$HOME/DerivedData/$SCHEME" \
| xcbeautify
# store_test_results needs JUnit XML: xcbeautify writes test-results/junit.xml
- run:
name: Run unit tests
command: |
xcodebuild test \
-scheme "$SCHEME" \
-destination "$DESTINATION" \
-clonedSourcePackagesDirPath "$HOME/spm-cache" \
-derivedDataPath "$HOME/DerivedData/$SCHEME" \
-resultBundlePath TestResults.xcresult \
| xcbeautify --report junit --report-path test-results
- store_test_results:
path: test-results
- store_artifacts:
path: TestResults.xcresult
destination: test-results
workflows:
ios-pipeline:
jobs:
- build-and-test:
filters:
branches:
only:
- main
- develop
Nota: il valore resource_class: your-org/mac-runner deve corrispondere esattamente alla resource class che hai creato nella dashboard di CircleCI. Se non corrisponde, i job rimarranno in coda a tempo indeterminato.
Passo 5: ottimizza con caching e parallelismo
Uno dei maggiori vantaggi di un runner self-hosted è il caching persistente. Poiché il filesystem del runner è persistente, non devi caricare e scaricare le cache come fai con le risorse cloud di CircleCI. Tuttavia, ci sono ottimizzazioni aggiuntive per massimizzare la velocità delle build.
Sfrutta i DerivedData persistenti
Poiché il disco del runner persiste tra una build e l'altra, i DerivedData sono già memorizzati in cache automaticamente. Usa un percorso coerente:
# In your config.yml steps, always use a consistent DerivedData path:
- run:
name: Build with persistent cache
command: |
xcodebuild build \
-scheme "$SCHEME" \
-destination "$DESTINATION" \
-derivedDataPath ~/DerivedData/"$SCHEME" \
-clonedSourcePackagesDirPath ~/spm-cache \
| xcbeautify
# Periodically clean old DerivedData on the runner (cron job):
# 0 3 * * 0 find ~/DerivedData -mindepth 1 -maxdepth 1 -mtime +7 -exec rm -rf {} +
Persistenza del workspace tra i job
Usa i workspace di CircleCI per passare i prodotti compilati a un job di test, che può girare su un altro Mac della stessa resource class:
jobs:
build:
machine: true
resource_class: your-org/mac-runner
steps:
- checkout
- run:
name: Build for testing
command: |
xcodebuild build-for-testing \
-scheme "MyApp" \
-destination "generic/platform=iOS Simulator" \
-derivedDataPath DerivedData \
| xcbeautify
# Pass only the built products, not the whole DerivedData
- persist_to_workspace:
root: .
paths:
- DerivedData/Build/Products
test:
machine: true
resource_class: your-org/mac-runner
steps:
- attach_workspace:
at: .
- run:
name: Run the tests built by the previous job
command: |
xcodebuild test-without-building \
-xctestrun "$(ls DerivedData/Build/Products/*.xctestrun | head -n 1)" \
-destination "platform=iOS Simulator,name=iPhone 17,OS=latest" \
| xcbeautify --report junit --report-path test-results
- store_test_results:
path: test-results
workflows:
build-test:
jobs:
- build
- test:
requires:
- build
Esecuzione parallela dei test
- run:
name: Run tests in parallel
command: |
# Xcode clones the simulator and runs test classes on up to 4 clones
xcodebuild test \
-scheme "MyApp" \
-destination "platform=iOS Simulator,name=iPhone 17,OS=latest" \
-parallel-testing-enabled YES \
-maximum-parallel-testing-workers 4 \
-derivedDataPath ~/DerivedData/MyApp \
| xcbeautify
Test splitting di CircleCI
Per suite di test di grandi dimensioni, il test splitting di CircleCI distribuisce le classi di test tra task paralleli. Ogni task richiede un proprio runner, quindi parallelism: 3 richiede tre Mac nella resource class; su un solo Mac i task vengono eseguiti uno dopo l'altro:
jobs:
test:
machine: true
resource_class: your-org/mac-runner
# One task per runner: 3 tasks need 3 Macs in this resource class
parallelism: 3
steps:
- checkout
- run:
name: Split test classes and run this task's share
command: |
# One XCTest class per file, named like the file (LoginTests.swift)
CLASSES=$(circleci tests glob "MyAppTests/**/*Tests.swift" \
| xargs -n1 basename | sed 's/\.swift$//' \
| circleci tests split)
# -only-testing takes Target/Class identifiers, not file paths
ONLY_TESTING=""
for CLASS in $CLASSES; do
ONLY_TESTING="$ONLY_TESTING -only-testing:MyAppTests/$CLASS"
done
xcodebuild test \
-scheme "MyApp" \
-destination "platform=iOS Simulator,name=iPhone 17,OS=latest" \
$ONLY_TESTING \
| xcbeautify --report junit --report-path test-results
- store_test_results:
path: test-results
Esempi di workflow
Ecco esempi di workflow completi e pronti per la produzione per scenari CI/CD iOS comuni.
Pipeline completa di build, test e deploy iOS
version: 2.1
jobs:
lint:
machine: true
resource_class: your-org/mac-runner
steps:
- checkout
- run:
name: Run SwiftLint
command: swiftlint lint --reporter json > swiftlint-results.json || true
- store_artifacts:
path: swiftlint-results.json
build-and-test:
machine: true
resource_class: your-org/mac-runner
environment:
# Xcode for this job, without sudo
# (preinstalled Xcode; for another version, use the path from `xcodes installed`)
DEVELOPER_DIR: "/Applications/Xcode.app/Contents/Developer"
steps:
- checkout
- run:
name: Resolve dependencies
command: |
xcodebuild -resolvePackageDependencies \
-scheme "MyApp" \
-clonedSourcePackagesDirPath ~/spm-cache
- run:
name: Build and test
command: |
xcodebuild test \
-scheme "MyApp" \
-destination "platform=iOS Simulator,name=iPhone 17,OS=latest" \
-clonedSourcePackagesDirPath ~/spm-cache \
-derivedDataPath ~/DerivedData/MyApp \
-resultBundlePath TestResults.xcresult \
-parallel-testing-enabled YES \
| xcbeautify --report junit --report-path test-results
- store_test_results:
path: test-results
- store_artifacts:
path: TestResults.xcresult
deploy-testflight:
machine: true
resource_class: your-org/mac-runner
environment:
DEVELOPER_DIR: "/Applications/Xcode.app/Contents/Developer"
steps:
- checkout
- run:
name: Install dependencies
command: bundle install
# MATCH_PASSWORD and the App Store Connect API key variables
# (ASC_KEY_ID, ASC_ISSUER_ID, ASC_KEY_CONTENT) come from a CircleCI
# context or the project's environment variables
- run:
name: Build and upload to TestFlight
command: bundle exec fastlane beta
workflows:
ios-pipeline:
jobs:
- lint
- build-and-test:
requires:
- lint
- deploy-testflight:
requires:
- build-and-test
filters:
branches:
only: main
Esempio di integrazione con Fastlane
Se usi Fastlane per l'automazione delle tue build, ecco come integrarlo con il tuo runner self-hosted CircleCI:
# Fastfile (fastlane/Fastfile)
default_platform(:ios)
platform :ios do
desc "Run tests"
lane :test do
scan(
scheme: "MyApp",
device: "iPhone 17",
derived_data_path: File.expand_path("~/DerivedData/MyApp"),
result_bundle: true,
output_directory: "./test_output",
# store_test_results reads JUnit XML
output_types: "junit",
output_files: "junit.xml"
)
end
desc "Build and push to TestFlight"
lane :beta do
# App Store Connect API key: no Apple ID password or 2FA on the runner
app_store_connect_api_key(
key_id: ENV["ASC_KEY_ID"],
issuer_id: ENV["ASC_ISSUER_ID"],
key_content: ENV["ASC_KEY_CONTENT"]
)
match(type: "appstore", readonly: true)
increment_build_number(
build_number: ENV["CIRCLE_BUILD_NUM"]
)
gym(
scheme: "MyApp",
export_method: "app-store",
derived_data_path: File.expand_path("~/DerivedData/MyApp")
)
pilot(skip_waiting_for_build_processing: true)
end
end
# .circleci/config.yml using Fastlane
version: 2.1
jobs:
fastlane-test:
machine: true
resource_class: your-org/mac-runner
steps:
- checkout
- run:
name: Install dependencies
command: bundle install
- run:
name: Run Fastlane tests
command: bundle exec fastlane test
- store_test_results:
path: ./test_output
- store_artifacts:
path: ./test_output
fastlane-deploy:
machine: true
resource_class: your-org/mac-runner
steps:
- checkout
- run:
name: Install dependencies
command: bundle install
- run:
name: Deploy to TestFlight
command: bundle exec fastlane beta
workflows:
ios-workflow:
jobs:
- fastlane-test
- fastlane-deploy:
requires:
- fastlane-test
filters:
branches:
only: main
Confronto delle prestazioni
Ecco un confronto dettagliato di prestazioni e costi tra le risorse macOS cloud di CircleCI e un Mac Mini M4 self-hosted di MyRemoteMac:
Benchmark dei tempi di build
| Scenario | Mac Mini M4 self-hosted | CircleCI Cloud macOS | Miglioramento |
|---|---|---|---|
| Clean build (app media) | 5 min | 14 min | 2,8 volte più veloce |
| Build incrementale | 1,5 min | 14 min (senza cache) | 9,3 volte più veloce |
| Risoluzione delle dipendenze SPM | 5 sec (in cache su disco) | 3-5 min (download ogni volta) | ~60 volte più veloce |
| Suite di unit test (500 test) | 2,5 min | 8 min | 3,2 volte più veloce |
| Tempo di attesa in coda | 0 sec | 30s - 5 min | Istantaneo |
Analisi dei costi mensili
| Dimensione del team | Costo MyRemoteMac | Build/mese | Costo CircleCI Cloud | Risparmio mensile |
|---|---|---|---|---|
| Sviluppatore singolo | $85/mese | 100 build (10 min in media) | $120/mese | $35/mese |
| Team piccolo (5) | $85/mese | 500 build (10 min in media) | $600/mese | $515/mese |
| Team medio (15) | $229/mese (M4 Pro) | 1500 build (10 min in media) | $1.800/mese | $1.571/mese |
| Enterprise (50+) | $458/mese (2x M4 Pro) | 5000+ build | $6.000+/mese | $5.542+/mese |
Prezzi My Remote Mac in USD, tasse escluse.
In sintesi: alla tariffa CircleCI della classe m4pro.medium (200 crediti, circa $0,12 al minuto, a ottobre 2026), una build da 10 minuti costa circa $1,20, quindi un Mac mini M4 dedicato a $85/mese (USD, tasse escluse) costa meno a partire da circa 71 build al mese. Le cache calde di un Mac persistente riducono anche il tempo che il team attende per ogni build.
Risoluzione dei problemi comuni
Il runner si disconnette o appare "Offline"
Il runner può perdere la connessione dopo un problema di rete, un crash o un riavvio. Se avviato nel dominio gui, torna solo quando il suo utente accede; la configurazione headless del Passaggio 2 lo evita. Controlla il servizio e il suo log:
# Check the service (use gui/ instead of user/ if you started it
# from a desktop session)
launchctl print user/$(id -u)/com.circleci.runner
# View the runner log
tail -50 "$HOME/Library/Logs/com.circleci.runner/runner.log"
# Restart the service
launchctl kickstart -k user/$(id -u)/com.circleci.runner
# If the token was revoked, create a new one, put it in
# ~/Library/Preferences/com.circleci.runner/config.yaml and restart
circleci runner token create your-org/mac-runner mac-mini-m4
resource_class non trovata o job bloccati in coda
Se i job restano in coda con "No matching runner found", la resource class nella tua configurazione non corrisponde a quella della dashboard:
# Verify the exact resource class name in the CircleCI web app:
# Runners (sidebar) lists your resource classes
# The resource_class in .circleci/config.yml must match exactly:
# resource_class: your-org/mac-runner (case-sensitive!)
# Check your runner is online:
circleci runner instance list your-org/mac-runner
# Common mistakes:
# - Wrong namespace (org name vs personal namespace)
# - Typo in resource class name
# - Runner is offline or token is invalid
# - Using 'docker' executor instead of 'machine: true'
Errori di code signing di Xcode
Il code signing su una macchina CI richiede un'attenta gestione del keychain. Il processo del runner potrebbe non avere accesso al keychain di login:
# Option 1: Use Fastlane Match (recommended)
# In your Fastfile:
match(type: "appstore", readonly: true)
# Option 2: Manual keychain management in your job steps
- run:
name: Setup code signing
command: |
# Decode and import the certificate
echo "$BUILD_CERTIFICATE_BASE64" | base64 --decode > /tmp/cert.p12
# Create a temporary keychain
security create-keychain -p "ci" /tmp/ci.keychain
security set-keychain-settings -lut 21600 /tmp/ci.keychain
security unlock-keychain -p "ci" /tmp/ci.keychain
# Import the certificate
security import /tmp/cert.p12 -P "$P12_PASSWORD" \
-A -t cert -f pkcs12 -k /tmp/ci.keychain
# Let codesign use the key without a GUI prompt
security set-key-partition-list -S apple-tool:,apple:,codesign: \
-s -k "ci" /tmp/ci.keychain
security list-keychain -d user -s /tmp/ci.keychain
# Install the provisioning profile (Xcode 16 and later location)
PROFILES=~/Library/Developer/Xcode/UserData/Provisioning\ Profiles
mkdir -p "$PROFILES"
echo "$PROVISIONING_PROFILE_BASE64" | base64 --decode \
> "$PROFILES/profile.mobileprovision"
Il simulatore non si avvia o va in timeout
I simulatori possono entrare in uno stato errato sulle macchine CI a lunga esecuzione. Resettali tra una build e l'altra:
# Add a pre-build step to clean simulators
- run:
name: Reset simulators
command: |
xcrun simctl shutdown all 2>/dev/null || true
xcrun simctl erase all 2>/dev/null || true
# If a specific runtime is missing, reinstall it:
xcodebuild -downloadPlatform iOS
# List available simulators
xcrun simctl list devices available
Spazio su disco in esaurimento
Le build di Xcode generano quantità significative di dati. Configura una pulizia automatica sul tuo runner:
# Check available disk space
df -h /
# Clean DerivedData folders unused for a week
find ~/DerivedData ~/Library/Developer/Xcode/DerivedData \
-mindepth 1 -maxdepth 1 -mtime +7 -exec rm -rf {} +
# Delete simulators the current Xcode no longer supports
xcrun simctl delete unavailable
# List simulator runtimes, then delete the ones you no longer test on
xcrun simctl runtime list
# xcrun simctl runtime delete <runtime-identifier>
# Clean Homebrew cache
brew cleanup --prune=7
# Set up a weekly cron job for automatic cleanup
(crontab -l 2>/dev/null; echo "0 4 * * 0 find ~/DerivedData -mindepth 1 -maxdepth 1 -mtime +7 -exec rm -rf {} + ; /opt/homebrew/bin/brew cleanup --prune=7") | crontab -