Pivotal Cloud Foundry Support

 View Only

 How to define custom environment variable STORE for an app with the value “TEST-%CF_INSTANCE_INDEX%”?

Jochen Damzog's profile image
Jochen Damzog posted Sep 23, 2019 09:39 AM

We use cloud foundry with java buildpack as app runtime. We would like to pass a custom environment variable STORE to the application with the value “TEST-%CF_INSTANCE_INDEX%” where CF_INSTANCE_INDEX should be replaced by the CF variables value. How can this be achieved best?

 

CF docs talk about "Configure app initialization", see https://docs.cloudfoundry.org/devguide/deploy-apps/deploy-app.html#profile however the method described there is not support by the java buildpack.

Daniel Mikusa's profile image
Daniel Mikusa

>CF docs talk about "Configure app initialization", see https://docs.cloudfoundry.org/devguide/deploy-apps/deploy-app.html#profile however the method described there is not support by the java buildpack.

 

That doc note is incorrect. You can use a `.profile` script with *any* buildpack. It's functionality provided by the foundation not the buildpack.

 

The trouble with the Java buildpack is that it's not easy to make it work because of where the `.profile` script needs to live and the way that for Java apps you push a WAR or JAR file. The `.profile` script needs to be in the root of what you push, which means it needs to be in the root of your WAR or JAR, which can be a pain depending on how you build the WAR or JAR file.

 

See Additional Info in this KB for details on how to make it work with a JAR or WAR.

 

Aside from that, you could initialize the value in your app. If you're using Spring, that might be using SpEL or by combining a couple properties in your `application.properties` or `application.yml` file.

 

Hope that helps!