Skip to main content

Using contexts and variables

Variables represent values which change throughout the execution of a program.

A global variable is a system variable which can be accessed by any module or function. It retains its value after the function or program using it has completed execution.

Information noteWarning: Note that the globalMap is error-prone in parallel execution. Be cautious when using globalMap.put("key","value") and globalMap.get("key") to create your own global variables and then retrieve their values in your Jobs, especially after an Iterate connection with the parallel execution option enabled.

A context variable is a variable which is defined by the user for a particular context. Depending on the circumstances the Job or Route is being used in, you might want to manage it differently for various execution types, known as contexts (Prod and Test in the example given below). For instance, there might be various testing stages you want to perform and validate before a Job or Route is ready to go live for production use.

Information noteNote:

General advices for using context variables:

  • Use small pieces of data in context variables.
  • Avoid putting code in context variables.
  • Use appropriate variable types rather than the default type String, for example, the type Password for a password to enhance security, the type File or Directory for a file path or directory to avoid possible unwanted escaping.
  • Avoid using double quotes around a string value in general. However, double quotes must be used if
    • the string contains an escape character and you want the unescaping to happen.
    • the string has a leading or a trailing double quote that is part of the variable value.

A context is characterized by parameters. These parameters are mostly context-sensitive variables which will be added to the list of variables for reuse in the component-specific properties on the Component view through the Ctrl+Space keystrokes.

Talend Studio offers you the possibility to create multiple context data sets. Furthermore you can either create context data sets on a one-shot basis from the context tab of a Job or Route, or you can centralize the context data sets in the Contexts node of the Repository tree view in order to reuse them in different Jobs or Routes.

For a Job, you can define the values of your context variables when creating them, or load your context parameters dynamically, either explicitly using the tContextLoad component or implicitly using the Implicit Context Load feature, when your Jobs are executed.

Information noteNote: When loading context parameters dynamically, the parameter values will be loaded from the specified file or database and the parameter values statically defined in Talend Studio, or in Talend Management Console in the case of Talend Cloud context parameters, will not take effect.

This section describes how to create contexts and variables and define context parameter values.

For an example of loading context parameters dynamically using the tContextLoad component, see Context.

For an example of loading context parameters dynamically using the Implicit Context Load feature, see .

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!