Dev > PaaS > CloudFoundry > PCF
Jul 25, 2020
Jul 25, 2020
N/A Views
MD
warning
この記事は2年以上前に更新されたものです。情報が古くなっている可能性があります。

cf envの結果が次のような場合に、

$ cf env billing-job

System-Provided:
VCAP_SERVICES: {
 "elephantsql": [
  {
   "binding_name": null,
   "credentials": {
    "hostname": "satao.db.elephantsql.com",
    "jdbcUrl": "jdbc:postgresql://satao.db.elephantsql.com:5432/foo?user=xyz\u0026password=abc",
    "name": "foo",
    "password": "abc",
    "port": 5432,
    "uri": "postgres://xyz:abc@satao.db.elephantsql.com:5432/foo",
    "username": "xyz"
   },
   "instance_name": "billing-db",
   "label": "elephantsql",
   "name": "billing-db",
   "plan": "turtle",
   "provider": null,
   "syslog_drain_url": null,
   "tags": [
    "postgresql",
    "postgres",
    "elephantsql"
   ],
   "volume_mounts": []
  }
 ]
}
...

billing-dbサービスインスタンスのurijqで取得したい時、

echo ${VCAP_SERVICES} | jq -r '.[][] | select(.instance_name == "billing-db") | .credentials.uri'

でOK。

Taskで参照したい場合は、

cf run-task billing-job -c "echo \${VCAP_SERVICES} | jq -r '.[][] | select(.instance_name == \"billing-db\") | .credentials.uri'" 

CF CLI v7の場合は、

cf7 run-task billing-job -c "echo \${VCAP_SERVICES} | jq -r '.[][] | select(.instance_name == \"billing-db\") | .credentials.uri'" 
Found a mistake? Update the entry.
Share this article: