currently in my react-native app I configure two lanes using fastlane: beta and production. I'm using react-native-config for different environment configs (stored in 2 files: .env.beta and .env.production). How can I let fastlane know which env file should be used for each lane ?
2 Answers
If you asking how to set environment variables before you call a command to build your app, you can do this in your Fastfile. In your Fastfile, before you call the fastlane action to build your app, set the ENV['ENVFILE'] variable to point to your .env.X file. See the react-native-config docs on environments.
lane :build_beta do
ENV['ENVFILE'] = '.env.beta'
build_ios_app(...) # you may be using `gym` instead.
end
lane :build_production do
ENV['ENVFILE'] = '.env.production'
build_ios_app(...) # you may be using `gym` instead.
end
Better yet, if the lane is exactly the same, you may want to call it with the config option from the command line:
# call me from the command line like: `fastlane build_sonlexqts_app config:beta`
lane :build_sonlexqts_app |options|
config = options[:config]
unless %w(beta production).include?(config)
UI.user_error!("#{config} is invalid. Please pass either 'beta' or 'production'")
end
ENV['ENVFILE'] = ".env.#{config}"
build_ios_app(...) # you may be using `gym` instead.
end
I managed to get react-native-config to pick up the correct config file using the environment variables feature provided by fastlane by using fastlane [lane] --env [beta|production].
-
It's working only when put .env files into fastlane folder. Commented Apr 28, 2021 at 8:54
-
This doesn't get passed to react native config, it gets passed to the fastlane process. In order to then pass it to react native config, ENVFILE should be set– ToshCommented Oct 13, 2021 at 10:45