Environment variable not expanding in openshift

It seems that if I use a command like:

rhc env set VARIABLE="$OPENSHIFT_DATA_DIR/file"

the directory reference variable never expands, and as a result, I cannot use it for my application. Is there any way to fix this?

EDIT

As @ timo.rieber pointed out in his answer, this will not work because the variable is resolved locally where it does not matter. Actually:

$ 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 also does not work (i.e., the extension does not occur when it is used by the process), even if this time it is correctly installed.

+4
source share
3 answers

:

$OPENSHIFT_DATA_DIR . , , ​​ .

, $OPENSHIFT_DATA_DIR. . :

user@machine:~$ rhc env list

user@machine:~$ rhc env set VARIABLE="file"
Setting environment variable(s) ... done

user@machine:~$ rhc env list
VARIABLE=file

user@machine:~$ rhc env unset VARIABLE
Removing environment variables is a destructive operation that may result in loss of data.
VARIABLE

Are you sure you wish to remove the environment variable(s) above from application 'yourapp'?(yes|no):yes

Removing environment variable(s) ... done

user@machine:~$ rhc env list

:

:

1. ,

user@machine:~$ rhc env set MY_ENV_VAR_FOR_BASE_DIR="OPENSHIFT_DATA_DIR"
Setting environment variable(s) ... done

2. ,

user@machine:~$ rhc env set MY_TARGET_FOLDER="file"
Setting environment variable(s) ... done

3. ( python)

(InteractiveConsole)
>>> import os

>>> os.environ.get("MY_ENV_VAR_FOR_BASE_DIR")
'OPENSHIFT_DATA_DIR'

>>> os.environ.get("OPENSHIFT_DATA_DIR")
'/var/lib/openshift/your_user_dir/app-root/data/'

>>> os.environ.get("MY_TARGET_FOLDER")
'file'

>>> os.path.join(os.environ.get(os.environ.get("MY_ENV_VAR_FOR_BASE_DIR")), os.environ.get("MY_TARGET_FOLDER"))
'/var/lib/openshift/your_user_dir/app-root/data/file'
+2

, "rhc env set...", node - "undefined", "export FOO". .

0

Despite the fact that this question is quite old, I decided that I would probably post a solution now. Environment variables expand in OpenShift modules, as they would in a shell using the $ (VAR) syntax, so you can set the DATABASE_URL variable like that;

oc set env dc service -e 'DATABASE_URL=mysql://user:pass@$(MARIADB_SERVICE_HOST):$(MARIADB_SERVICE_PORT)/dbname'

then these variables will be expanded upon deployment.

0
source

All Articles