Environment Variables
Environment variables allow you to securely pass secrets and configuration to your build steps. This recipe shows how to configure environment variables at both the pipeline and step levels.
Complete YAML
Section titled “Complete YAML”name: Deploy Buildplatform: iosenvironment: xcode: "16.4"
triggers: - push
steps: - name: Build run: fastlane build env: APP_ENV: production API_TOKEN: $API_TOKENYAML-Level Environment Variables
Section titled “YAML-Level Environment Variables”You can define variables at the pipeline level, available to all steps:
name: Environment Variables Exampleplatform: iosenvironment: xcode: "16.4" variables: DEPLOYMENT_TARGET: "13.0" MINIMUM_IOS_VERSION: "13.0" BUILD_CONFIGURATION: "Release"
triggers: - push
steps: - name: Build run: | xcodebuild \ -workspace MyApp.xcworkspace \ -scheme MyApp \ -configuration $BUILD_CONFIGURATION \ buildStep-Level Environment Variables
Section titled “Step-Level Environment Variables”Variables defined in a step are only available to that step:
name: Step-Level Variablesplatform: iosenvironment: xcode: "16.4"
triggers: - push
steps: - name: Build with debug settings run: fastlane build env: DEBUG: "1" VERBOSE: "true"
- name: Build with production settings run: fastlane build env: DEBUG: "0" DEPLOYMENT_TARGET: "13.0"Using Environment Variables from Dashboard
Section titled “Using Environment Variables from Dashboard”Environment variables are configured in the RunnerHub dashboard at workspace or app scope. Reference them in your YAML using $VARIABLE_NAME:
name: Secure Deployplatform: iosenvironment: xcode: "16.4"
triggers: - push
steps: - name: Build and deploy run: fastlane beta env: APP_STORE_CONNECT_API_KEY: $APP_STORE_CONNECT_API_KEY FASTLANE_PASSWORD: $FASTLANE_PASSWORD GITHUB_TOKEN: $GITHUB_TOKENKey Points
Section titled “Key Points”- Dashboard Variables: Created in dashboard (Workspace → Environment tab or App → Environment tab), available as environment variables with
$VARIABLE_NAMEsyntax - YAML Variables: Literal values defined in the pipeline YAML file
- Variable Scope: Pipeline-level
envapplies to all steps; step-levelenvapplies only to that step; app-scoped variables override workspace-scoped - Masking: Environment variable values are automatically masked in build logs and output
Environment Variable Examples
Section titled “Environment Variable Examples”Fastlane with API Keys
Section titled “Fastlane with API Keys”name: Deploy to TestFlightplatform: iosenvironment: xcode: "16.4" variables: FASTLANE_USER: $APPLE_ID_EMAIL FASTLANE_PASSWORD: $APPLE_ID_PASSWORD FASTLANE_SESSION: $FASTLANE_SESSION
triggers: - push
steps: - name: Deploy to TestFlight run: fastlane beta env: APP_STORE_CONNECT_API_KEY: $APP_STORE_CONNECT_API_KEYCocoaPods with Private Specs
Section titled “CocoaPods with Private Specs”steps: - name: Install pods from private repo run: pod install env: GIT_AUTHORIZATION_TOKEN: $GITHUB_TOKEN COCOAPODS_USERNAME: $COCOAPODS_USER COCOAPODS_PASSWORD: $COCOAPODS_PASSWORDXcodebuild with Custom Settings
Section titled “Xcodebuild with Custom Settings”name: Signed Buildplatform: iosenvironment: xcode: "16.4" variables: DEVELOPMENT_TEAM: $APPLE_TEAM_ID PROVISIONING_PROFILE_SPECIFIER: $PROFILE_NAME CODE_SIGN_IDENTITY: "iPhone Developer"
triggers: - push
steps: - name: Build signed run: | xcodebuild \ -workspace MyApp.xcworkspace \ -scheme MyApp \ -configuration Release \ buildDebugging Environment Variables
Section titled “Debugging Environment Variables”To inspect what variables are available, use the env command:
steps: - name: Print environment run: env | grep -E "APP_|FASTLANE_|API_" | sortBest Practices
Section titled “Best Practices”- Use dashboard environment variables for all sensitive data
- Keep secrets out of YAML — use variable references only
- Document required secrets in your repository README
- Rotate secrets regularly for security
- Limit secret access — only expose needed secrets to steps that use them