.env
, .env.default
and .env.{environment}
, where environment
is supplied by the flag --env
in the fastlane
command.Fastfile
, I need fastlane to load my environment files, that are located in the parent directory..env.{environment}
file, when {environment}
changes according to what I pass in the --env
flag.This one worked for me:
before_all
inside my platform
block: before_all do |lane|
Dotenv.overload '../../.env'
environment = lane_context[SharedValues::ENVIRONMENT]
unless environment.nil?
puts "Load .env file of #{environment}"
Dotenv.overload '../../.env.' + environment
end
end
.env
file in the fastlane
directory.The reason to create an empty .env
is documented in my empty .env
file:
TL;DR: do NOT delete this empty file
This file is blank to make Fastlane define the
SharedValue::ENVIRONMENT
variable, which is part of ourfastlane/Fastfile
configurations.As you can see in Fastlane's
cli_tools
, Fastlane removes the--env
index fromARGV
pretty early so we can't know what the user passed to the--env
parameter.Unfortunatly, Fastlane search the .env files only in the
fastlane
folder and in it's parent folder (theios
folder, in our case). It means that, in our project, Fastlane won't find any .env files. (Source)When Fastlane fails to find .env files, it does not call the function
load_dot_envs_from
, which is responsible to define theSharedValue::ENVIRONMENT
variable, which we use inside our Fastfile (Source)This file is a hack that will make Fastlane find an empty
.env
file. It will then set theSharedValue::ENVIRONMENT
to the ARGV value. We then useSharedValue::ENVIRONMENT
inside Fastlane to load the right file from the right place.