How to override values ​​inside fastlane application file using .env files

We need to override the values ​​in the fastlane file in certain situations, for example. Use a different Apple account to publish the application, but no official document has been registered.

+4
source share
3 answers

The easiest way to do this is to use environment variables:

Use Appfileas follows:

apple_id ENV["APPLE_ID"] || "default@company.com"
app_identifier ENV["APP_IDENTIFIER"] || "com.company.default"

When you now call fastlane without environment variables:

fastlane beta

it will use the default values ​​provided ( default@company.com)

to set another value that you can use

APP_IDENTIFIER="com.custom.app" fastlane enterprise

, , .

+10

, .env .

:

require('dotenv')
Dotenv.load '../.env'

app_identifier "original.app.identifier" # The bundle identifier of your app
apple_id "account@example.com" # Your Apple email address
team_name "originalTeamName"
team_id "originalTeamID"

unless ENV["N42_FASTLANE_APP_IDENTIFIER"].nil?
  app_identifier ENV["N42_FASTLANE_APP_IDENTIFIER"]
end

unless ENV["N42_FASTLANE_APPLE_ID"].nil?
  apple_id ENV["N42_FASTLANE_APPLE_ID"]
end

unless ENV["N42_FASTLANE_TEAM_NAME"].nil?
  team_name ENV["N42_FASTLANE_TEAM_NAME"]
end

unless ENV["N42_FASTLANE_TEAM_ID"].nil?
  team_id ENV["N42_FASTLANE_TEAM_ID"]
end

van .env :

N42_FASTLANE_APPLE_ID="anotherAccount@example.com"
+2

Appfile : https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Appfile.md.

team_id s, username app_identifier Fastfile, :

lane :example_lane do
cert(
      username: "email@company.com",
      team_id: "ABCDE123"
    )    
sigh(
      username: "email@company.com",
      team_id: "ABCDE123",
      app_identifier: "com.company.example.app"
      )
gym(
      export_team_id: "ABCDE123"
      ) 
end
0

All Articles