AppMaker:每个部署的环境变量?获取部署名称?

AppMaker: environment variables per deployment ? Get the deployment name?

前段时间我问过这个:How to check in both server-side and client-side scripts if we are in preview mode or deployed version

因为我希望在我的代码中有不同的逻辑,无论是否是预览模式。

答案是 "preview mode is just another deployment and each deployment has its own Drive table, store some env variables there"。这是真的,成功了。

问题:驱动表 don't exist anymore

过去几个月我没有使用 AppMaker,所以我可能错过了新功能:

感谢您的回答

这是一个未记录的解决方案。它不是最好的,也不推荐长期使用,因为它将来可能会发生变化,但是,要直接回答您的问题,您可以通过服务器脚本获取部署名称。将以下内容放在服务器脚本中:

function getDeployment() {
  var deploymentName = app.a.a.a[13].name;
  return deploymentName;
}

然后在UI中插入一个按钮,在按钮的onClick事件处理程序中添加以下内容:

google.script.run.withSuccessHandler(function(result){
  console.log(result);  
}).getDeployment();

预览应用程序,对其进行测试,您应该会得到 预览。将应用程序发布到部署并对其进行测试,您应该获得部署名称。希望对您有所帮助!

SQL 没有任何变化。预览和部署使用单独的数据集。在table 中放入一个设置记录并分别分配部署或预览值就足够了。每个新预览都将使用预览数据,每个新部署都将使用生命数据。

可以使用 Google script properties service 存储部署唯一的环境变量。