使用 mvn function:run 和环境变量在本地运行 GCP Cloud Function。

huangapple 未分类评论47阅读模式
英文:

Running gcp cloud funtion locally using mvn function:run with ENV variables

问题

我想在本地运行 Google Cloud 函数,使用以下的 Maven 插件命令:

mvn function:run

在运行时,我使用以下语法提供了一些环境变量,但是我在函数代码中无法读取这些值。系统方法 System.getenv("VAR1") 返回了空值。

mvn function:run -DVAR1=value1 -DVAR2=value2 -DrunFunction.target=com.sample.MyFunction

有人可以指导/纠正我吗?

英文:

I want to run google cloud function locally, using function maven plugin command as below

mvn function:run

While running this I am giving some env variables with below syntax but I am not able to read these values in my function code. The system method System.getenv("VAR1") returning null value.

mvn function:run -DVAR1=value1 -DVAR2=value2 -DrunFunction.target=com.sample.MyFunction

Can anyone guide/correct me on this?

答案1

得分: 0

要获取您使用 -D 标志传递的值,您需要使用 System.getProperty() 而不是 System.getenv()

英文:

To get the values you are passing using the -D flag, you will need to use System.getProperty() instead of System.getenv().

huangapple
  • 本文由 发表于 2020年7月24日 00:06:21
  • 转载请务必保留本文链接:https://java.coder-hub.com/63058536.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定