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