How to set environment variables in fastlane?

Parth Adroja picture Parth Adroja · Feb 7, 2018 · Viewed 12.5k times · Source

I had read the documents but I am still confused where to set the environment variables in the fastfile or the bash_profile. Can you please help me out with that?

What I want to achieve is to set the apple developer credentials in fastfile and should not ask again if any user takes pull of my code and try to build it.

I am writing this in fastlane file. Let me know if I am wrong.

default_platform(:ios)

platform :ios do

ENV["FASTLANE_DONT_STORE_PASSWORD"] = "1"
ENV["FASTLANE_USER"] = ""
ENV["FASTLANE_PASSWORD"] = ""

desc "GENERATE SCREENSHOT"
lane :Snaps do
capture_screenshots
end

end

Answer

Bilal picture Bilal · Feb 7, 2018

You can add environment variables in before_all. Try this.

platform :ios do
  before_all do
    ENV["FASTLANE_DONT_STORE_PASSWORD"] = "1"
    ENV["FASTLANE_USER"] = ""
    ENV["FASTLANE_PASSWORD"] = ""
  end

  desc "GENERATE SCREENSHOT"
  lane :Snaps do
    capture_screenshots
  end
end

To not store your keys in git, you can pass all parameters of all actions using environment variables.

You can edit your ~/.bash_profile to include something like

export FASTLANE_DONT_STORE_PASSWORD ="1"
export FASTLANE_USER =""
export FASTLANE_PASSWORD =""