How to set environment variables in fastlane?

20,320

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 =""
Share:
20,320

Related videos on Youtube

Parth Adroja
Author by

Parth Adroja

#Geek #Gamer #Developer #Traveller #Explorer I Code in Swift and Obj-C for iOS, watchOS, tvOS.

Updated on July 09, 2022

Comments

  • Parth Adroja
    Parth Adroja almost 2 years

    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
    
  • Parth Adroja
    Parth Adroja about 6 years
    So either of the above way is correct right? Any flag to set for match password?
  • Iulian Onofrei
    Iulian Onofrei about 6 years
  • Bilal
    Bilal about 6 years
    First one is correct as far as you are not adding your fastfile to git (you don’t want to push you logins and password to repo). Second is good because your credentials stays on your local machine. I am not aware of anything like match password.
  • Parth Adroja
    Parth Adroja about 6 years
    @Bilal For match password you can use MATCH_PASSWORD env variable.
  • Parth Adroja
    Parth Adroja about 6 years
    I did as you mentioned. I added above to git and used other system to generate the build. But it still asks for Apple dev credentials. I doubt it's not setting above env vars.
  • MEnnabah
    MEnnabah over 5 years
    I think the second way will run the environment variable with every bash script I execute in terminal. Am I wrong?