stonedauwg
stonedauwg

Reputation: 1407

cant get environment variables from file working in fastlane

Trying to follow examples and docs from fastlane regarding env vars and dotenv files, but I cant get any ENV variables to work in fastlane. My Fastfile has this to test a variable usage:

lane :test do
  var1 = ENV["CRASHLYTICS_API_TOKEN"]
  puts "+++#{var1}"
end

My .env.default file sits in the same directory as the Fastfile and simply has this one line:

CRASHLYTICS_API_TOKEN="123abc"

What syntax am I missing here? When I run the test lane above, all that prints is +++. I am expecting +++123abc. Maybe a Ruby issue - I don't know Ruby. I tried explicitly installing the dotenv gem on Mac and it didn't make any difference.

Upvotes: 0

Views: 3312

Answers (2)

Konstantin
Konstantin

Reputation: 386

if you use command line (in Unix) to make env variable don't forget use export keyword, like this:

export CRASHLYTICS_API_TOKEN=123abc

otherwise fastlane can't see the variable.

Upvotes: 1

stonedauwg
stonedauwg

Reputation: 1407

Found out the problem was not having the Fastfile and .env.default files inside a 'fastlane' directory. I was running them from a directory they were both in, but that directory was not named 'fastlane'. Note that the "fastlane init" command does produce this folder for you. Still, wonder why you must have your files inside that folder especially when you consider fastlane does, in fact, execute the lane in your Fastfile perfectly fine (well, other than this ENV issue) when the Fastfile is in a random folder. I must have missed this requirement in the docs. I likely got in this mess due to experimenting with fastlane's import action, trying to reference other Fastfiles.

Would love to get a confirmation from @KrauseFx if the folder is indeed required.

Upvotes: 2

Related Questions