Environment variables to substitute values in context.xml

Hello.

I should set environment variables for tomcat process or for IDE (IntelliJ) process to substitute values in context.xml? Connection data from context.xml used by Cuba studio plugin to connect to DB? Or just Tomcat instance?

Hi,

CUBA Studio connects to the database when performing the following operations: generating database scripts, performing data schema check before starting CUBA Application, executing “Create database”, “Update database”.
So if you need to hide the password from the build.gradle - you need to set environment variables for the IDE process (or globally).

Tomcat server used for debug also needs to know connection parameters to the database. So you need to set environment variable(s) also for Tomcat, or globally on the developer machine.

Also note that CUBA 7.2 has implemented the following improvements which made easier to use environment variables for connection to the database:

  1. New projects don’t use data source configured in context.xml anymore. Database connection parameters are not specified through application properties.
    https://doc.cuba-platform.com/manual-7.2/db_connection.html

  2. And application properties can now be taken from the environment variables: https://doc.cuba-platform.com/manual-7.2/app_properties.html#setting_app_properties

Thank you!

But I still have problem, when I define datasource properties in app.properties in core module, I leave it blank:
cuba.dataSource.username =
cuba.dataSource.password =
and define env variable in shell before starting IDE
set cuba.dataSource.username=username
set cuba.dataSource.password=password
When debug session with tomcat starts, I see configuration in HikariCP config defined in shell. But when IDE try to update database (task Check cuba database in run config) I get “Database server connection error” in IDE, and run process stops. If I remove Check database task then tomcat starts successfull. I cannot update database when DB password not defined in sources?

Hi,
To make Create Database and Update Database actions work, you need to define placeholder as follows in the app.properties:

cuba.dataSource.password=${ORACLE_PASSWORD}
cuba.dataSource.host=${ORACLE_DB_HOST}
...

And then define environment variables: ORACLE_DB_HOST and ORACLE_PASSWORD.
See this recently completed ticket: https://github.com/cuba-platform/cuba-gradle-plugin/issues/137

Unfortunately Studio does not currently support placing database connection parameters to environment variables with such its functions as “Generate Database Scripts” and internal checks performed before CUBA Application run configuration is run. So you won’t be able to generate update scripts without putting actual values to the app.properties.
I’ve created a Studio ticket to support that: https://youtrack.cuba-platform.com/issue/STUDIO-8458