To pass parameters from the command line to your lane, use the following syntax:
fastlane [lane] key:value key2:value2
fastlane deploy submit:false build_number:24
To access those values, change your lane decleration to also include |options|
lane :deploy do |options|
...
if options[:submit]
# Only when submit is true
end
...
increment_build_number(build_number: options[:build_number])
...
end
To switch lanes while executing a lane, use the following code:
lane :deploy do |options|
...
build(release: true) # that's the important bit
hockey
...
end
lane :staging do |options|
...
build # it also works when you don't pass parameters
hockey
...
end
lane :build do |options|
scheme = (options[:release] ? "Release" : "Staging")
ipa(scheme: scheme)
end
fastlane
takes care of all the magic for you. You can call lanes of the same platform or a general lane outside of the platform
definition.
Passing parameters is optional.
Additionally, you can retrieve the return value. In Ruby, the last line of the lane
definition is the return value. Here is an example:
lane :deploy do |options|
value = calculate(value: 3)
puts value # => 5
end
lane :calculate do |options|
...
2 + options[:value] # the last line will always be the return value
end
You can get value from shell commands:
output = sh("pod update")
Within your Fastfile
you can import another Fastfile
using 2 methods:
Import a Fastfile
from a local path
import "../GeneralFastfile"
override_lane :from_general do
...
end
Import from another git repository, which you can use to have one git repo with a default Fastfile
for all your project
import_from_git(url: 'https://github.com/KrauseFx/fastlane')
# or
import_from_git(url: 'git@github.com:MyAwesomeRepo/MyAwesomeFastlaneStandardSetup.git',
path: 'fastlane/Fastfile')
lane :new_main_lane do
...
end
You should import the other Fastfile
on the top above your lane declarations. When defining a new lane fastlane
will make sure to not run into any name conflicts. If you want to overwrite an existing lane (from the imported one), use the override_lane
keyword.
You can define environment variables in a .env
or .env.default
file in the same directory as your Fastfile
. Environment variables are loading using dotenv. Here's an example.
WORKSPACE=YourApp.xcworkspace
HOCKEYAPP_API_TOKEN=your-hockey-api-token
fastlane
also has a --env
option that allows loading of environment specific dotenv
files. .env
and .env.default
will be loaded before environment specific dotenv
files are loaded. The naming convention for environment specific dotenv
files is .env.<environment>
For example, fastlane <lane-name> --env development
will load .env
, .env.default
, and .env.development
The different actions can communicate with each other using a shared hash. You can access them in your lanes with the following code.
Replace VARIABLE_NAME_HERE
with any of the following.
lane_context[SharedValues::LANE_NAME] # The name of the current lane (stays the same when switching lanes)
lane_context[SharedValues::BUILD_NUMBER] # Generated by `increment_build_number`
lane_context[SharedValues::SNAPSHOT_SCREENSHOTS_PATH] # Generated by `snapshot`
lane_context[SharedValues::PRODUCE_APPLE_ID] # The Apple ID of the newly created app
lane_context[SharedValues::IPA_OUTPUT_PATH] # Generated by `ipa`
lane_context[SharedValues::DSYM_OUTPUT_PATH] # Generated by `ipa`
lane_context[SharedValues::SIGH_PROFILE_PATH] # Generated by `sigh`
lane_context[SharedValues::SIGH_UDID] # The UDID of the generated provisioning profile
lane_context[SharedValues::HOCKEY_DOWNLOAD_LINK] # Generated by `hockey`
lane_context[SharedValues::DEPLOYGATE_URL] # Generated by `deploygate`
lane_context[SharedValues::DEPLOYGATE_APP_REVISION] # Integer, generated by `deploygate`
lane_context[SharedValues::DEPLOYGATE_APP_INFO] # Hash, generated by `deploygate`
To get information about the available lane variables, run fastlane action [action_name]
.
Sometimes you might have a lane that is used from different lanes, for example:
lane :production do
...
build(release: true)
appstore # Deploy to the AppStore
...
end
lane :beta do
...
build(release: false)
crashlytics # Distribute to testers
...
end
lane :build do |options|
...
ipa
...
end
It probably doesn't make sense to execute the build
lane directly using fastlane build
. You can hide this lane using
private_lane :build do |options|
...
end
This will hide the lane from:
fastlane lanes
fastlane list
fastlane docs
And also, you can't call the private lane using fastlane build
.
The resulting private lane can only be called from another lane using the lane switching technology.
Just rename the folder to .fastlane
in case you don't want it to be visible in the Finder.
Add this to the top of your Fastfile
.
actions_path '../custom_actions_folder/'
The documentation was moved to Appfile.md.
You can set the environment variable FASTLANE_SKIP_UPDATE_CHECK
to skip the update check.
If you are using Git for this project, we recommend that you keep the fastlane
configuration files in your repository. You may want to add the following lines to your .gitignore
file to exclude some generated and temporary files:
# Fastlane temporary profiling data
/fastlane/report.xml
# Deliver temporary error output
/fastlane/Error*.png
# Deliver temporary preview output
/fastlane/Preview.html
# Snapshot generated screenshots
/fastlane/screenshots/*/*-portrait.png
/fastlane/screenshots/*/*-landscape.png
/fastlane/screenshots/screenshots.html
# Frameit generated screenshots
/fastlane/screenshots/*/*-portrait_framed.png
/fastlane/screenshots/*/*-landscape_framed.png