Using Environment Variables to Override Application Property Values
The use of environment variables to assign new values to your application properties at runtime is a handy method that you can use to test your application with multiple data sets.
Step 1: Create environment variables for your application properties
export <app-property-name>="<value>"
For example, if your application property name is username, run export username="abc@xyz.com" or export USERNAME="abc@xyz.com"
- Since special characters (such as `! | < > &@ `) are shell command directives, if they appear in value, enclosing the value in double quotes tells the system to treat such characters as literal values instead of shell command directives.
- The app-property-name must match the application property exactly or it can use all uppercase letters. For example, the application property, Message, can either be entered as Message or MESSAGE, but not as message.
- If you want to use a hierarchy for your application property, be sure to use underscores (_) between each level instead of the dot notation. For example, for an application property named x.y.z, the environment variable name should be either x_y_z or X_Y_Z.
Step 2: Set FLOGO_APP_PROPS_ENV=auto environment variable
To use the environment variables during app runtime, set the FLOGO_APP_PROPS_ENV=auto environment variable.
FLOGO_APP_PROPS_ENV=auto ./<app-binary>
For example, FLOGO_APP_PROPS_ENV=auto MESSAGE="This is variable 1." LOGLEVEL=DEBUG ./Timer-darwin-amd64
Setting the FLOGO_APP_PROPS_ENV=auto directs your app to search the list of environment variables for each application property by matching the environment variable name to the application property name. When it finds a matching environment variable for a property, the app pulls the value for the property from the environment variable and runs the app with those values. Hence, it is mandatory that the application property name exactly match the environment variable name for the property.
Application properties that were not set as environment variables will pick up the default values set for them in the app. You will see a warning message similar to the following in the output: <property_name> could not be resolved. Using default values.