Updated on 2024-04-29 GMT+08:00

Configuring Environment Variables

This topic describes how to configure and use environment variables.

Application Scenario

Configure job parameters. If a parameter belongs to multiple jobs, you can extract this parameter as an environment variable. Environment variables can be imported and exported.

The roles that can configure workspace environment variables in the simple and enterprise mode are as follows:

Simple mode: Both developers and administrators can create and edit environment variables in a workspace. This mode does not distinguish the development environment from the production environment. Developers can modify environment variables.

Enterprise mode: Only administrators can create or edit environment variables in a workspace.

Importing Environment Variables

This function is available only if the OBS service is available. If OBS is unavailable, variables can be imported from the local PC.

  1. Log in to the DataArts Studio console by following the instructions in Accessing the DataArts Studio Instance Console.
  2. On the DataArts Studio console, locate a workspace and click DataArts Factory.
  3. In the navigation tree on the left, choose Specifications.
  4. Click Environment Variables. On the Environment Variables page, click Import.
  5. In the Import Environment Variable dialog box, select an environment variable file from OBS or a local path and the duplicate name policy.

    Figure 1 Importing Environment Variables

Configuration Method

  1. Log in to the DataArts Studio console by following the instructions in Accessing the DataArts Studio Instance Console.
  2. On the DataArts Studio console, locate a workspace and click DataArts Factory.
  3. In the navigation tree on the left, choose Specifications.
  4. On the Environment Variable page, set the variables or constants listed in Table 1 and click Save.

    The difference between a variable and a constant lies in whether their values need to be reconfigured when they are imported to another workspace or project.

    • The value of a variable (such as workspace name) varies depending on the workspace. When exporting a variable from a workspace and import it to another workspace, you must reconfigure its value.
    • The value of a constant in different workspaces is the same. When importing a constant to another workspace, you do not need to reconfigure its value.
    Figure 2 Configuring environment variables

    Table 1 Configuring environment variables

    Parameter

    Mandatory

    Description

    Parameter

    Yes

    The parameter name must be unique, consist of 1 to 64 characters, and contain only letters, digits, underscores (_), and hyphens (-).

    The parameter name must be in the format set in Configuring Script Variables. For example, if the format set in the script variable definition is ${dlf.}, the parameter name must be set to dlf.xxx.

    Value

    Yes

    Parameter values support constants and EL expressions but do not support system functions. For example, 123 and abc are supported. If the parameter value is a string, add double quotation marks (""), for example, "05".

    For details about how to use EL expressions, see Expression Overview.

    Description

    No

    Parameter description

    After configuring an environment variable, you can add, edit, or delete it.

    • Add: Click Add to add an environment variable.
    • Edit: If the parameter value is a constant, change the parameter value in the text box. If the parameter value is an EL expression, click next to the text box to edit the EL expression. Click Save.
    • Delete: Click next to the parameter value text box to delete the environment variable.

How-Tos

The configured environment variables can be used in either of the following ways:

  1. ${Environment variable}
  2. #{Evn.get("Environment variable")}

Example

Context:

  • A job named test has been created in the DataArts Factory module.
  • An environment variable has been added. The parameter name is job and the parameter value is 123.
  1. Open test and drag a Create OBS node from the node library.
  2. On the Node Properties tab page, configure the node properties.

    Figure 3 Configuring parameters for the Create OBS node

  3. Click Save and then Monitor to monitor the running status of the job.