0

I have a java application. Which needs json object to start the app. In my local environment I pass this through VM options but not able to figure out this in cloud foundry.

I tried passing in .profile file but it did not work. In this file I provide export variablename="{jsonObject}"

Any help will be appreciated.

Thank you

Nikita
  • 1
  • Hi, welcome to Stack Overflow. Please see this example of [how to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) – Apache Jan 16 '20 at 19:31

2 Answers2

1

There are a few ways in which you can pass Environment Variables in a cloud foundry

  1. Using the set-env variable command using cf commandline: The general syntax is cf set-env APP_NAME ENV_VAR_NAME ENV_VAR_VALUE
  2. Using Manifest file: If you are using manifest file with cf push you can set the environamet valriables in it like so. Official documenttaion can be found here

    env: ENV_VARIABLE1: value1 ENV_VARIABLE1: value2

  3. Using mtar descriptor: This might be specific to SAP Cloud Foundry, if you are using SAP Cloud platrom and are deploying applications as mtar, in the mtar deployment descriptor, you can set the PROPERTIES field in under the deployment section to add additional env varables. Additional documentation can be found here. e.g.

    properties: POPULATE_ALBUM_REPOSITORY: true

Shiva
  • 6,677
  • 4
  • 36
  • 61
0

Adding to the answer above you can use also:

cf set-env myapplication env1=val1 env2=val2 env3=val3 ...

where ... is another set of env=val to set more than one variable in the same line

For large JSON variables you can use:

export MYVAR=`cat mylarge.json`
cf set-env myapplication MIKEVAR "$MYVAR"

Finally, in order to rewrite the entire configuration you can use the following example:

cf curl -X PUT /v2/apps/<app-guid> -d '{"environment_json":{"ENV1":"VAL1", "ENV2": "VAL2"}}'

That overwrites everything and replaces it with what is in the JSON, so if you have existing env variables you'd have to include those as well as the new ones you want to set.