Maurice
Maurice

Reputation: 792

Fastlane not initializing environment variables --env

I am using fastlane for my iOS application. In this case I have an xcode project with multiple targets. Therefor I want to use some different variables in fastlane. However the variables are not initialized.

I have set up custom .env files for each target. For example the .env file of Target1:

ENV_TARGET_NAME=MyAppName
ENV_TARGET_NAME_SHORT=MyAppNameShort

The .env file is called .env.Target1 and is set in the fastlane folder. I already tried to see if this is working by placing the file in the root folder of my project.

My fastlane files looks like the following:

fastlane_version "1.109.0"

before_all do
     ensure_git_status_clean
     skip_docs
end

lane :QA_all do
    sh "fastlane QA --env Target1"
    sh "fastlane QA --env Target2"
    sh "fastlane QA --env Target3"
end

lane :accept_all do
    sh "fastlane QA --env Target1"
    sh "fastlane QA --env Target2"
    sh "fastlane QA --env Target3"
end

lane :live_all do
    sh "fastlane QA --env Target1"
    sh "fastlane QA --env Target2"
    sh "fastlane QA --env Target3"
end

desc "Builing version with TEST environment"
lane :QA do |options|
    target_name = ENV['ENV_TARGET_NAME']


/* Rest of the file */

-- Update

Using options[:target_name] is getting the target name. However I am sending this to a .sh file to move to the ipa to the correct folder.

sh "sh ./scripts/ipa_deployment.sh #{version_number} #{target_name}

When I set the target_name hardcoded like "MyAppName" I will see the variable inside the .sh file. However when I set it from the options[:target_name] the variable is empty. Someone any idea why this is happening?

Upvotes: 1

Views: 3025

Answers (1)

Sulfkain
Sulfkain

Reputation: 5119

You are doing it wrong. As documentation says https://docs.fastlane.tools/advanced/#environment-variables It's loads first .env and then your .env.myTarget

But look what are you doing, your run fastlane QA_all (f.ex.) This instance of fastlane has no env at all! That's why you are having an empty string.

Even, when you are doing sh ... this will run on another, I'm not sure, process?¿?, the output will not be the same as which you started fastlane.

If you want to run 3 construction / deploy scripts for 3 differents Targets (Apps I understand). You should go better for a script where you call your 3 fastlane configurations.

I have not tried, but should be serialized on the script, launching your first fastlane Target1, and when it's finished, running the 2 and so on... but better test this.

I hope this will help you ;).

Upvotes: 0

Related Questions