Working with environment variables
Requires Compose August 2021 Service Release 03 or later.
Environment variables allow developers to build more portable expressions, custom ETLs, and Compose configurations, which is especially useful when working with several environments such as DTAP (Development, Testing, Acceptance and Production). Different environments (for example, development and production) often have environment-specific settings such as database names, schema names, and Replicate task names. Variables allow you to easily move projects between different environments without needing to manually configure the settings for each environment. This is especially useful if many settings are different between environments. For each project, you can use the predefined environment variables or create your own environment variables.
Database and schema name variables are supported with the following objects:
- Reusable transformations
- Custom ETLs (Data warehouse and Data marts)
- Mappings lookups
- Mappings and model expressions
- Data mart settings
Limitations and considerations
- Values for predefined variables will be shown in the Compose user interface, but user-defined variables will be shown in variable format (for example, $$${myVariable}).
- Variable names are case sensitive and can include alphanumeric characters, underscores, and periods only.
-
User-defined variable definitions will not be included in projects exported as JSON files or in projects exported as CSV files. However, user-defined variable names will be included in the relevant places in the exported files.
See also: Exporting and importing projects using the CLI and Migrating objects as CSV files.
-
Exported CSV objects that are associated with predefined environment variables (for example, a mapping database and schema) cannot contain user-defined environment variables.
For instance, this is not allowed:
Name Landing Zone Database Schema MyMapping $$${MyDatabase} $$${MySchema} See also: Migrating objects as CSV files.
Locations and names of predefined variables
Predefined variables are located in the following places:
Compose environment_variables CLI guidelines
The procedures below describe how to manage environment variables using the Compose CLI. When using the Compose CLI, make sure to adhere to the following guidelines:
-
Before running any environment_variables commands, run the Connect command to establish a connection to the Compose Server. For more information on this command, see Connecting to Qlik Compose server.
-
Variable names should be specified in the CLI without dollar signs or curly brackets. So, for example, assuming the name of your landing database is MyLanding, $$${database.MyLanding.database} should be specified as database.MyLanding.database.
-
When setting a variable with the Compose CLI, any variable names and values with spaces (both user-defined and predefined) must be specified in quotation marks. This means, for example, that all data warehouse variables must be specified with quotation marks as their names always contain a space (for example, "database.Data Warehouse.serverName").
-
When setting a Boolean value, use --boolVal instead of --val. For example, to set database.Data Warehouse.connectionInputModeStandard to "True", specify:
--var "database.Data Warehouse.connectionInputModeStandard" --boolVal true
Working with predefined variables only
When working with predefined environment variables only, the flow is as follows:
- In the source environment:
- Configure your project as desired.
Run the following command to write the predefined environment variables to a JSON file (replacing projectName with the name of your Compose project and JsonFileLocation with the full path of your JSON file):
ComposeCli environment_variables --command writePredefined --project projectName --jsonFile JsonFileLocation
Information noteFor security reasons, Compose never writes encrypted passwords to files.
-
-
Create a deployment package or export the project using the Compose CLI.
See also: Project deployment and Exporting a project.
-
-
In the target environment:
-
Deploy the project if you created a deployment package or import the project if you exported it using the Compose CLI.
See also: Project deployment and Importing a project.
-
Copy the JSON file created in the source environment to your preferred location.
-
Edit the JSON file and replace the variable values with the values you want to propagate to the target environment.
See also: Working with environment variables.
-
Run the following command to propagate the JSON file variables to the Compose user interface (replacing projectName with the name of your Compose project and JsonFileLocation with the full path of your edited JSON file):
ComposeCli environment_variables --command setALL --project projectName --jsonFile JsonFileLocationExample:
ComposeCli environment_variables --command setALL --project analytics --jsonFile C:\compose\compose-variables.jsonWarning noteRunning the setAll command will remove any existing environment variables that are not included in the JSON file. Therefore, if you want to make sure that such variables are not removed when setAll is run, add them to the JSON file.Tip noteYou can also set any variable by running the set command. This is especially useful if you do not want the JSON file to include passwords. In this case, you would need to run the following command (shown as an example):
ComposeCli environment_variables --command set --project MyProject --var encryptedPassword --val g56g56y563%When you set a password with the CLI, Compose encrypts the password first and then sets it.
-
Run the following command to apply the predefined environment variables and complete the process (replacing projectName with the name of your Compose project):
ComposeCli environment_variables --command applyPredefined --project projectName
-
Working with user-defined variables only
When working with user-defined environment variables only, the flow is as follows:
You can use user-defined variables in the following places:
- Expressions - in model, mappings (column expressions, data quality and filters) or data mart
- Lookup conditions and expressions
- Custom ETLs
To set user-defined variables:
- In the source environment:
In the Compose user interface, include your variable in an object that supports user-defined variables (for example, a Custom ETL in a data warehouse task or an expression), and save your settings.
Example: User-defined variable in a Custom ETL
UPDATE "ROSIE"."DWH2"."TSTG_Employees" SET "Title" = $$${myVar} WHERE "EmployeeID" < 150
For user-defined variables, use one of the following methods:
Method 1:
Set each variable individually by running the following command (replacing projectName with the name of your Compose project, varName with the variable name, and value with the variable value):
ComposeCli environment_variables --command set --project projectName --var varName --val valueExample:
ComposeCli environment_variables --command set --project MyProject --var myVar --val ManagerMethod 2:
Add the user-defined variables directly to the JSON file as described in Manually editing the JSON file below.
Generate the task(s) with the user-defined variables.
If you set the user-defined variables with the CLI, run the following command to write the user-defined variables to a JSON file (replacing projectName with the name of your Compose project and JsonFileLocation with the full path of your JSON file):
ComposeCli environment_variables --command writeCLISet --project projectName --jsonFile JsonFileLocationCreate a deployment package or export the project using the Compose CLI.
See also: Project deployment and Exporting a project.
-
In the target environment:
-
Deploy the project if you created a deployment package or import the project if you exported it using the Compose CLI.
See also: Project deployment and Importing a project.
-
Copy the JSON file created in the source environment to your preferred location.
-
Edit the JSON file and replace the variable values with the values you want to appear in the target environment.
See also: Working with environment variables.
-
Run the following command to propagate the JSON file variables to the Compose user interface (replacing projectName with the name of your Compose project and JsonFileLocation with the full path of your edited JSON file)::
ComposeCli environment_variables --command setALL --project projectName --jsonFile JsonFileLocationWarning noteRunning the setAll command will remove any existing environment variables that are not included in the JSON file. Therefore, if you want to make sure that such variables are not removed when setAll is run, add them to the JSON file. -
Generate the relevant tasks as well.
-
Working with both user-defined and predefined variables
When working with both user-defined and predefined environment variables, the flow is as follows:
- In the source environment:
- Configure your project as desired.
Run the following command to write the predefined environment variables to a JSON file (replacing projectName with the name of your Compose project and predefinedJsonFileLocation with the full path of the JSON file that you want to contain your predefined variables):
ComposeCli environment_variables --command writePredefined --project projectName --jsonFile predefinedJsonFileLocationIn the Compose user interface, add user-defined variables to supported objects (for example, a Custom ETL in a data warehouse task), and save your settings.
Example: User-defined variable in a Custom ETL
UPDATE "ROSIE"."DWH2"."TSTG_Employees" SET "Title" = $$${myVar} WHERE "EmployeeID" < 150
For user-defined variables, use one of the following methods:
Method 1:
Set each variable individually by running the following command (replacing projectName with the name of your Compose project, varName with the variable name, and value with the variable value):
ComposeCli environment_variables --command set --project projectName --var varName --val valueExample:
ComposeCli environment_variables --command set --project MyProject --var myVar --val ManagerMethod 2:
Add the user-defined variables directly to the JSON file as described in Manually editing the JSON file below.
Generate the task with the user-defined variable(s).
If you set the user-defined variables with the CLI, run the following command to write the user-defined variables to a JSON file (replacing projectName with the name of your Compose project and JsonFileLocation with the full path of the JSON file that you want to contain your user-defined variables):):
ComposeCli environment_variables --command writeCLISet --project projectName --jsonFile userDefinedJsonFileLocationCreate a deployment package or export the project using the Compose CLI.
See also: Project deployment and Exporting a project.
Information noteFor security reasons, Compose never writes encrypted passwords to files. -
In the target environment:
-
Deploy the project if you created a deployment package or import the project if you exported it using the Compose CLI.
See also: Project deployment and Importing a project.
-
Copy the JSON file created in the source environment to your preferred location.
-
Edit the JSON file and replace the variable values with the values you want to appear in the target environment.
See also: Working with environment variables.
-
Run the following command to propagate the JSON file variables to the Compose user interface (replacing projectName with the name of your Compose project and JsonFileLocation with the full path of your edited JSON file)::
ComposeCli environment_variables --command setALL --project projectName --jsonFile JsonFileLocationWarning noteRunning the setAll command will remove any existing environment variables that are not included in the JSON file. Therefore, if you want to make sure that such variables are not removed when setAll is run, add them to the JSON file. -
Generate all tasks with user-defined variables.
-
Run the following command to apply the predefined environment variables and complete the process (replacing projectName with the name of your Compose project):
ComposeCli environment_variables --command applyPredefined --project projectName
-
Removing environment variables
Run the "Remove" command if you set a variable that you no longer want to use in the target environment.
-
Run the following command:
ComposeCli environment_variables --command remove --var VarName --project projectNameExample:
ComposeCli environment_variables --command remove --var MyVariable --project MyProject -
Generate any task(s) configured with user-defined variables.
Manually editing the JSON file
Before you propagate the JSON file variables to the Compose user interface in the target environment, you need to edit the file and replace the source variable values with the target variable values. It might also be more convenient to create, edit and maintain the JSON file manually instead of (or in addition to) using the writeCLISet and writePredefined commands described above.
The JSON file is split into two sections: “predefinedVariables” and “userDefinedVariables”. When you edit the JSON file, make sure to put predefined variables in the “predefinedVariables” section and user-defined variables in the “userDefinedVariables” section. In addition, make sure to use standard JSON escaping conventions, as shown in the following example:
{
“predefined”: {
"databases.Data Warehouse.serverName": "myhostname"
},
“userDefined”: {
"variable": "value",
"var2": "val2"
}
Propagating the JSON file variables to the Compose user interface
After you have prepared your JSON file and copied it to your preferred location, perform the following procedure to propagate the variables to the Compose user interface:
-
Run the following command to propagate the JSON file variables to the Compose user interface (replacing projectName with the name of your Compose project and JsonFileLocation with the full path of your edited JSON file):
ComposeCli environment_variables --command setALL --project projectName --jsonFile JsonFileLocationExample:
ComposeCli environment_variables --command setALL --project MyProject --jsonFile C:\composeVariables\myVariables.jsonWarning noteRunning the setAll command will remove any existing user-defined environment variables from the user-interface, and reset any modified predefined environment variables that are not included in the JSON file to their previous values. -
If the JSON file contains predefined environment variables, run the following command (replacing projectName with the name of your Compose project):
ComposeCli environment_variables --command applyPredefined --project projectName -
If the JSON file contains user-defined environment variables, generate the associated task(s).