【问题标题】:How to override values inside fastlane's appfile using .env files如何使用 .env 文件覆盖 fastlane 的 appfile 中的值
【发布时间】:2016-05-05 17:59:47
【问题描述】:

在某些情况下,我们需要覆盖 fastlane 的 appfile 中的值,例如使用不同的苹果账号发布应用,但官方没有记录的方式。

【问题讨论】:

    标签: ios fastlane


    【解决方案1】:

    最简单的方法是使用环境变量:

    像这样使用Appfile

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

    当您现在在没有环境变量的情况下调用 fastlane 时:

    fastlane beta
    

    它将使用提供的默认值 (default@company.com)

    设置您可以使用的不同值

    APP_IDENTIFIER="com.custom.app" fastlane enterprise
    

    正如其他回复已经指出的那样,您始终可以为不同的环境设置多个通道,只需将不同的应用标识符或用户名传递给您调用的每个操作。

    【讨论】:

    • 将此与 --env 参数结合起来似乎是最舒适的方法
    • 是的!谢谢,很有帮助!
    【解决方案2】:

    我们找到了一种方法,使用主项目文件夹中被忽略的 .env 文件。

    它可以用来覆盖appfile中的值,如下所示:

    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
    

    在 .env 文件中设置新值如下:

    N42_FASTLANE_APPLE_ID="anotherAccount@example.com"
    

    【讨论】:

    • 我认为Dotenv.load 不是必需的,fastlane 原生支持 .env 文件。您应该使用--env 参数运行它。例如。你有一个.env.Production 文件。然后你可以像fastlane <lane_name_here> --env Production一样运行fastlane。
    • 不客气)没有很好的文档记录,但在“多个目标”部分提到了here
    【解决方案3】:

    Appfile 支持覆盖不同通道的值:https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Appfile.md

    您还可以在Fastfile 中指定不同的team_ids、usernames 和app_identifiers,例如:

    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
    

    【讨论】:

    • 我们知道这种方式,但希望只覆盖一个值(每台机器),而 git 中没有“脏”的 Appfile,也没有多个通道。
    猜你喜欢
    • 1970-01-01
    • 2015-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    • 2018-03-08
    • 2012-10-07
    • 1970-01-01
    相关资源
    最近更新 更多