为我的VCAP_SERVICES设置环境变量

问题描述 投票:0回答:2

Cloud-Foundry中,我已将mongo-secrets存储在CUPS中,并且我想在Mac中本地复制相同的内容

这是两个属性

vcap.services.mongo-creds.credentials.username=**
vcap.services.mongo-creds.credentials.password=**

在使用./gradlew bootRun在本地系统中运行我的应用程序之前,我给出了这两个命令来设置这些属性以启动应用程序

export vcap.services.mongo-creds.credentials.username=**
export vcap.services.mongo-creds.credentials.password=**

我在本地终端收到以下异常

arun$ export vcap.services.mongo-creds.credentials.username=***
-bash: export: `vcap.services.mongo-creds.credentials.username=**': not a valid identifier
arun$ 
linux macos cloudfoundry
2个回答
0
投票

我能够通过两次更正做到这一点

  1. 我将名称从mongo-creds更改为mongoCreds。我的Mac终端不接受连字符

  2. 我将dot.替换为underscore_,例如

export vcap_services_mongoCreds_credentials_username=***

应用程序能够提取这些变量


0
投票

Bash shell不允许点.或破折号-成为变量标识符的一部分。

因此,在您的export表达式中,当为变量vcap.services.mongo-creds.credentials.username定义值时,Bash会告诉您此变量的名称无效。

一个简单的解决方案是选择另一个变量名,或改用下划线_

但是要在Mac上具有相关的cf push开发人员经验,我建议您使用CF Local,而不是基于简单的Gradle命令构建自己的即席设置。使用CF Local,您将能够从远程Cloud Foundry基础继承服务绑定,包括使用cf cups创建的用户提供的服务。这应该非常适合您的用例!

© www.soinside.com 2019 - 2024. All rights reserved.