You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Expo EAS构建中向Maestro传递环境变量?

在Expo EAS中为Maestro传递环境变量的解决方案

方案1:构建前动态替换Maestro配置文件占位符

在EAS构建流程中添加预处理步骤,直接替换maestro.yml中的${APP_ID}为实际环境变量值,绕过Maestro的变量解析逻辑:

  1. 在项目package.json中添加预处理脚本:
"scripts": {
  "pre-maestro-test": "sed -i '' 's/${APP_ID}/'\"$APP_ID\"'/g' maestro.yml"
}

(注:Linux环境可简化为sed -i 's/${APP_ID}/'\"$APP_ID\"'/g' maestro.yml)

  1. 在eas.json的构建配置中指定测试命令:
{
  "build": {
    "production": {
      "scripts": {
        "test": "npm run pre-maestro-test && maestro test maestro.yml"
      }
    }
  }
}

方案2:通过EAS环境变量直接传递给Maestro命令

和本地执行逻辑对齐,显式在Maestro命令中传递变量:

  1. 在EAS Dashboard的项目Secrets中添加APP_ID,设置对应环境的应用ID。
  2. 在eas.json中配置测试脚本:
{
  "build": {
    "production": {
      "scripts": {
        "test": "maestro test -e APP_ID=$APP_ID maestro.yml"
      }
    }
  }
}

方案3:让Maestro读取系统环境变量

Maestro支持直接读取进程环境变量,只要EAS构建时APP_ID已注入:

  1. 在EAS Dashboard添加APP_ID为项目Secret。
  2. 在eas.json中显式声明要暴露的环境变量并执行测试:
{
  "build": {
    "production": {
      "env": {
        "APP_ID": "$APP_ID"
      },
      "scripts": {
        "test": "maestro test maestro.yml"
      }
    }
  }
}

关键注意事项

  • 可在测试脚本中添加echo $APP_ID验证变量是否正常加载。
  • 多环境场景可在eas.json的不同构建配置中绑定对应环境的APP_ID值,或通过Secrets分组管理。

内容的提问来源于stack exchange,提问作者RightHot

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 08:18:19