Early Access: The content on this website is provided for informational purposes only in connection with pre-General Availability Qlik Products.
All content is subject to change and is provided without warranty.
Skip to main content Skip to complementary content

Working with environment variables

Information note

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:

  1. In the source environment:
    1. Configure your project as desired.
    2. 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
    3. Information noteFor security reasons, Compose never writes encrypted passwords to files.
    1. Create a deployment package or export the project using the Compose CLI.

      See also: Project deployment and Exporting a project.

  1. In the target environment:

    1. 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.

    2. Copy the JSON file created in the source environment to your preferred location.

    3. 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.

    4. 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 JsonFileLocation

      Example:  

      ComposeCli environment_variables --command setALL --project analytics --jsonFile C:\compose\compose-variables.json
      Warning 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 note

      You 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.

    5. 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:

Information noteUser-defined variables should have the following format in the Compose user interface: $$${myVariable}

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:

  1. In the source environment:
    1. 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
    2. 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 value

      Example:  

      ComposeCli environment_variables --command set --project MyProject --var myVar --val Manager

       

      Method 2:

      Add the user-defined variables directly to the JSON file as described in Manually editing the JSON file below.

    3. Generate the task(s) with the user-defined variables.

    4. 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 JsonFileLocation
    5. Create a deployment package or export the project using the Compose CLI.

      See also: Project deployment and Exporting a project.

  2. In the target environment:

    1. 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.

    2. Copy the JSON file created in the source environment to your preferred location.

    3. 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.

    4. 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 JsonFileLocation
      Warning 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.
    5. Generate the relevant tasks as well.

Working with both user-defined and predefined variables

Warning noteEach time Compose writes to the JSON file, it overwrites the existing content. Therefore, when working with both user-defined and predefined variables, you need to specify the path to two different JSON files. For convenience, you can then merge the two files into a single JSON file while taking care to use the format described in Manually editing the JSON file below.

When working with both user-defined and predefined environment variables, the flow is as follows:

  1. In the source environment:
    1. Configure your project as desired.
    2. 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 predefinedJsonFileLocation
    3. Information noteFor security reasons, Compose never writes encrypted passwords to files.
    4. In 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
    5. 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 value

      Example:  

      ComposeCli environment_variables --command set --project MyProject --var myVar --val Manager

       

      Method 2:

      Add the user-defined variables directly to the JSON file as described in Manually editing the JSON file below.

    6. Generate the task with the user-defined variable(s).

    7. 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 userDefinedJsonFileLocation
    8. Create a deployment package or export the project using the Compose CLI.

      See also: Project deployment and Exporting a project.

  2. In the target environment:

    1. 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.

    2. Copy the JSON file created in the source environment to your preferred location.

    3. 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.

    4. 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 JsonFileLocation
      Warning 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.
    5. Generate all tasks with user-defined variables.

    6. 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.

Warning noteRemoving a predefined variable will reset it to its previous value. To prevent errors, make sure when you remove user-defined variables, to also edit or remove the custom ETL or expression where the variable is located.
  1. Run the following command:

    ComposeCli environment_variables --command remove --var VarName --project projectName

    Example:  

    ComposeCli environment_variables --command remove --var MyVariable --project MyProject
  2. 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"
}
Information noteEditing and saving the JSON file does not automatically set and apply the variables. To do this, run the 'SetAll' and 'ApplyPredefined' commands. If the JSON file also contains user-defined variables, you will need to generate the associated tasks as well. See below for details.

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:

  1. 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 JsonFileLocation

    Example:  

    ComposeCli environment_variables --command setALL --project MyProject --jsonFile C:\composeVariables\myVariables.json
    Warning 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.
  2. 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
  3. If the JSON file contains user-defined environment variables, generate the associated task(s).

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!