Over a million developers have joined DZone.

How to Set Environment Variables for a CloudFoundry App

· Cloud Zone

Download the Essential Cloud Buyer’s Guide to learn important factors to consider before selecting a provider as well as buying criteria to help you make the best decision for your infrastructure needs, brought to you in partnership with Internap.

We can set environment variables for an application that is deployed in CloudFoundry. For example if we want to pass a JAVA_OPTS environment variable with a value of -XX:MaxPermSize=256m. We have to use the env-add command of the vmc command-line tool. We specify the application name we want to set the environment variable for followed by a key=value pair.

In the following command we set a JAVA_OPTS environment variable for the website application:

$ vmc env-add website JAVA_OPTS="-XX:MaxPermSize=256m -XX:+CMSClassUnloadingEnabled"
Adding Environment Variable [JAVA_OPTS="-XX:MaxPermSize=256m -XX:+CMSClassUnloadingEnabled"]: OK
Stopping Application: OK
Staging Application: OK
Starting Application: OK
$

To see which environment variables are set we can use the env command. To delete a variable we use env-del and the name of the environment variable.

$ vmc env website
 
+-----------+----------------------------------------------------+
| Variable  | Value                                              |
+-----------+----------------------------------------------------+
| JAVA_OPTS | -XX:MaxPermSize=256m -XX:+CMSClassUnloadingEnabled |
+-----------+----------------------------------------------------+
 
$ vmc env-del website JAVA_OPTS
Deleting Environment Variable [BLOG_OPTS]: OK
Stopping Application: OK
Staging Application: OK
Starting Application: OK
$

 

 

The Cloud Zone is brought to you in partnership with Internap. Read Bare-Metal Cloud 101 to learn about bare-metal cloud and how it has emerged as a way to complement virtualized services.

Topics:

Published at DZone with permission of Hubert Klein Ikkink, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}