Overview
Jenkins is a popular open-source automation server. Thesetup_jenkins action helps configure fastlane to work seamlessly with Jenkins, handling keychains, code signing, and build artifacts.
Quick Start
Add this to the beginning of yourFastfile:
The setup_jenkins Action
Thesetup_jenkins action configures Xcode build tools for Jenkins integration. It only runs when the JENKINS_HOME or JENKINS_URL environment variables are detected.
What it Does
Unlocks Keychain
Unlocks the keychain from Jenkins’ Keychains and Provisioning Profiles Plugin
- Adds keychain to search list
- Sets as default keychain
- Configures match to use this keychain
Configures Output Directory
Sets output directory to
./output for:- IPA files (gym)
- Test results (scan)
- Archives (backup_xcarchive)
Sets Derived Data Path
Creates dedicated derived data at
./derivedData for:- Xcodebuild
- Gym
- Scan
- Carthage
- Slather
Parameters
Jenkins Configuration
Installing Jenkins
Install Required Plugins
Navigate to Manage Jenkins → Plugins and install:
- Keychains and Provisioning Profiles Plugin
- Git Plugin
- Credentials Plugin
- Environment Injector Plugin
Setting Up Keychains and Provisioning Profiles Plugin
Upload Keychain
- Go to Manage Jenkins → Credentials
- Click Add Credentials
- Select Apple Development Keychain
- Upload your keychain file
- Enter keychain password
Jenkinsfile Examples
Basic Pipeline
Advanced Pipeline with Multiple Lanes
Freestyle Project Configuration
For freestyle Jenkins jobs:Environment Configuration
Required Environment Variables
Set these in Jenkins credentials or job configuration:Environment Variables Set by setup_jenkins
These are automatically configured:Common Issues
Keychain Unlock Errors
Problem:User interaction is not allowed or keychain locked errors
Solution:
Code Signing Errors
Problem:No code signing identity found
Solution:
-
Verify keychain contains certificates:
-
Use match to sync certificates:
Timeout Errors
Problem: Build times out waiting for input Solution:Permission Errors
Problem: Jenkins user can’t access files Solution:Best Practices
1. Use Dedicated Build Nodes
Label macOS agents for iOS builds:2. Cache Dependencies
3. Separate Build Directories
Each Jenkins job gets its own workspace, preventing conflicts:4. Clean Up Old Builds
Configure Jenkins to discard old builds:5. Use Credentials Plugin
Store secrets in Jenkins credentials, not in code:Example Fastfile
Related Actions
- setup_ci - Generic CI setup
- unlock_keychain - Unlock keychain manually
- match - Code signing management
- is_ci - Detect CI environment