It seems that if I use a command like:
rhc env set VARIABLE="$OPENSHIFT_DATA_DIR/file"
the referenced directory variable is never expanded and as a result I can not use it for my app. Is there any way to fix this?
EDIT
As noted by @timo.rieber in his answer, this is not going to work because the variable is resolved locally, where it has no value. In fact:
$ rhc env set VARIABLE="$OPENSHIFT_DATA_DIR/file"
Setting environment variable(s) ... done
$ rhc env show VARIABLE
VARIABLE=/file
However, if I use single quotes to avoid immediate expansion:
$ rhc env set VARIABLE='$OPENSHIFT_DATA_DIR/file'
Setting environment variable(s) ... done
$ rhc env show VARIABLE
VARIABLE=$OPENSHIFT_DATA_DIR/file
Interestingly, this does not work as well (i.e. no expansion happens when it is used by the process) even if apparently this time it is correctly set.
Problem explanation:
The value of
$OPENSHIFT_DATA_DIR
gets resolved on your local computer. Most likely it will be empty as this variable is not set on your machine.It is not possible to read values of builtin server-side environment variables like
$OPENSHIFT_DATA_DIR
. Only externally set variables will be exposed. You can try this by the following example:Solution:
Set two environment variables and use them within your program code to build your path:
1. Define a first environment variable to define the builtin environment variable to read
2. Define a second environment variable to specify your folder within the given directory
3. Within your code (python example) build your path
I recall running "rhc env set ...", but my node express server was still seeing 'undefined' until I ran "export FOO". So try that.
Although this question is pretty old, I figured I would post what is probably the solution currently. The environment variables expand in OpenShift pods somewhat like they would in the shell using $(VAR) syntax, so you you could set a variable DATABASE_URL like;
then those variables will get expanded at deployment.