How to override values inside fastlane's appfile using .env files

删除回忆录丶 提交于 2019-12-03 07:34:33

The easiest way to do that is using environment variables:

Use an Appfile like this:

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 a different value you can use

APP_IDENTIFIER="com.custom.app" fastlane enterprise

Also as already pointed out by other replies, you can always have multiple lanes for different environments and just pass a different app identifier or username to each of the actions you're calling.

We found a way to do this, using a ignored .env file in the main project folder.

It can be used to override values in the appfile as follows:

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

New values van be set in the .env file as follows:

N42_FASTLANE_APPLE_ID="anotherAccount@example.com"

The Appfile has support for overriding values for different lanes: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Appfile.md.

You can also specify different team_ids, usernames and app_identifiers in your Fastfile, for example:

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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!