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

帅比萌擦擦* 提交于 2020-02-24 04:37:10

问题


Some times ago I asked this: How to check in both server-side and client-side scripts if we are in preview mode or deployed version

Because I wanted in my code to have different logic whether it is the preview mode or not.

The answer was "preview mode is just another deployment and each deployment has its own Drive table, store some env variables there". That was true and made the trick.

Problem: Drive tables don't exist anymore.

I have not been working with AppMaker the past months so maybe I have missed new features:

  • how can I set environment variables per deployment ? (so I can make a difference between my prod deployment and my pre-prod deployment)

  • is there a way to get the current deployment name from the code ?

Thanks for your answers


回答1:


Deployment unique environment variables can be stored using the Google script properties service.




回答2:


This is an undocumented solution. It's not the best and neither recommended for long term usage because it can change in the future, however, to answer your question directly, you can get the deployment name via server scripting. Put the following on a server script:

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

Then insert a button in the UI, add the following to the onClick event handler of the button:

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

Preview the app, test it and you should get Preview. Publish the app to a deployment and test it, you should get the deployment name. I hope it helps!




回答3:


Nothing has changed with SQL. The preview and deployment work with separate data sets. It is enough to put one setting record in a table and assing deployment or preview value respectively. Each new preview will work with preview data and each new deployment will work with life data.



来源:https://stackoverflow.com/questions/51627648/appmaker-environment-variables-per-deployment-get-the-deployment-name

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