You can define context variables for a particular Job or Route in two ways:
Using the Contexts view of the Job or Route. See How to define context variables in the Contexts view.
Using the F5 key from the Component view of a component. See How to define variables from the Component view.
The Contexts view is positioned among the configuration tabs below design workspace.
The Contexts tab view shows all of the variables that have been defined in the current Job or Route and context variables imported into the current Job.
From this view, you can manage your built-in variables:
Create and manage built-in contexts.
Create, edit and delete built-in variables.
Reorganize the context variables.
Add built-in context variables to the Repository.
Import variables from a Repository context source for use in the current Job.
Edit Repository-stored context variables and update the changes to the Repository.
Remove imported Repository variables from the current Job or Route.
The following example will demonstrate how to define two contexts named Prod and Test and a set of variables - host, port, database, username, password, and table_name - under the two contexts for a Job.
Open the Job in the design workspace.
Select Window > Show view > Talend > Contexts to open the Contexts view in the Integration perspective.
Click the [+] button at the top right corner.
The [Configure Contexts] dialog box opens and a context named Default is created by default.
Select the default context and click Edit to rename it, Prod in this example. Click OK.
In the open dialog box, click New... and enter Test in the [New Context] dialog box, click OK.
Select the check box preceding the context you want to set as the default context.
You can also set the default context by selecting the context name from the Default context environment list in the Contexts tab view.
If needed, move a context up or down by selecting it and clicking the Up or Down button.
In this example, set Test as the default context and move it up.
Click OK to validate your context definition and close the dialog box.
The newly created contexts are shown in the context variables table of the Contexts view.
Repeat the above steps to create as many new contexts as needed.
If you do not want to define the values of each new context from scratch, you can create the first context and define all its values as when you create a new one all the parameters of the context selected as default are copied to the new context. You can then modify the values of the new context as needed.
Click the [+] button at the bottom of the Contexts view to add lines in the table.
Click in the Name field and enter the name of the variable you are creating.
Name the first variable host for this example.
From the Type list, select the type of the variable.
If needed, click in the Comment field and enter a comment to describe the variable.
Click in the Value field and enter the variable value under each context.
For different variable types, the Value field appear slightly different when you click in it and functions differently:
String (default type)
Editable text field
Drop-down list box with two options: true and false
Character, Double, Integer, Long, Short, Object, BigDecimal
Editable text field
Editable text field, with a button to open the [Select Date & Time] dialog box.
Editable text field, with a button to open the [Open] dialog box for file selection.
Editable text field, with a button to open the [Browse for Folder] dialog box for folder selection.
List of Value
Editable text field, with a button to open the [Configure Values] dialog box for list creation and configuration.
Editable text field; text entered appears encrypted.
It is recommended that you enclose the values of string type variables between double quotation marks to avoid possible errors during Job execution.
If needed, select the check box next to the variable of interest and enter the prompt message in the corresponding Prompt field. This allows you to see a prompt for the variable value and to edit it at the execution time.
You can show/hide a Prompt column of the table by clicking the black right/left pointing triangle next to the relevant context name.
Repeat the above steps to define all the variables for the different contexts.
port, type String,
database, type String,
username, type String,
password, type Password,
table_name, type String.
All the variables created and their values under different contexts are displayed in the table and are ready for use in your Job. You can further edit the variables in this view if needed.
You can also add a built-in context variable to the Repository to make it reusable across different Jobs. For more information, see How to add a built-in context variable to the Repository.
The quickest way to create a single context variable is to use the F5 key from the Component view. The following example demonstrates how to create a context variable while configuring a file path for a component in a Job.
On the relevant Component view, place your cursor in the field you want to parameterize.
Press F5 to display the [New Context Parameter] dialog box:
Give a Name to this new variable, fill in the Comment field if needed, and choose the Type.
Enter a Prompt to be displayed to confirm the use of this variable in the current Job execution (generally used for test purpose only), select the Prompt for value check box to display the prompt message and an editable value field at the execution time.
If you filled in a value already in the corresponding properties field, this value is displayed in the Default value field. Else, type in the default value you want to use for one context.
Click Finish to validate.
Go to the Contexts view tab. Notice that the context variables tab lists the newly created variables.
The newly created variables are listed in the Contexts view.
The variable name should follow some typing rules and should not contain any forbidden characters, such as space character.
The variable created this way is automatically stored in all existing contexts, but you can subsequently change the value independently in each context. For more information on how to create or edit a context, see Defining contexts.