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: The implementation of the globalMap object is not synchronized by default. This may bring thread safety issues when you are using global variables created via the globalMap object in your Job. However, as the globalMap object is not shared among Jobs, if you are running multiple child Jobs in parallel, using the globalMap object inside each of the child Jobs can mitigate thread safety issues during parallelization. For more information about parallelization, see Using parallelization to optimize Job performance.

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!