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

一笑奈何 提交于 2019-12-21 01:19:09

问题


We have the need to override values in fastlane's appfile in certain situations, e.g. to use a different apple account for publication of the app, but there is no documented official way.


回答1:


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.




回答2:


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"



回答3:


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


来源:https://stackoverflow.com/questions/37057268/how-to-override-values-inside-fastlanes-appfile-using-env-files

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