Skip to content

Instantly share code, notes, and snippets.

@joshdholtz
Last active September 27, 2024 08:50
Show Gist options
  • Save joshdholtz/cd077ccdddb608af00eb2466259e7ac0 to your computer and use it in GitHub Desktop.
Save joshdholtz/cd077ccdddb608af00eb2466259e7ac0 to your computer and use it in GitHub Desktop.
Using Dotenv and environment variables with fastlane
STUFF = this is some stuff
CONFIG = this is config 1
CONFIG = this is config 2
SOME_API_TOKEN = 123456789
fastlane_require 'dotenv'
before_all do
Dotenv.overload '.env.secret'
end
lane :test do
# Loaded from .env (by fastlane)
puts "STUFF: #{ENV['STUFF']}"
# Loaded from .env.secret (by us in before_all)
puts "SOME_API_TOKEN: #{ENV['SOME_API_TOKEN']}"
# Loaded from .env.(<env>) where <env> is passed in from `fastlane test --env <env>` (by fastlane)
# Ex: `fastlane test --env config` loads .env.config1
puts "CONFIG: #{ENV['CONFIG']}"
end
fastlane_require 'dotenv'
before_all do
Dotenv.overload '.env.secret'
end
$: fastlane test
STUFF: this is some stuff
SOME_API_TOKEN: 123456789
CONFIG:
$: fastlane test --env config1
STUFF: this is some stuff
SOME_API_TOKEN: 123456789
CONFIG: this is config 1
$: fastlane test --env config2
STUFF: this is some stuff
SOME_API_TOKEN: 123456789
CONFIG: this is config 2
@kambala-decapitator
Copy link

@mgrachev FYI you have extra characters in the URL that prevent it from opening directly

@mgrachev
Copy link

@mgrachev FYI you have extra characters in the URL that prevent it from opening directly

Thanks! Fixed.

@endrits079
Copy link

Is it possible to load env files outside of fastlane directory?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment