You can define context variables for a particular Job in two ways:
Using the Contexts view of the Job. 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.
If you cannot find the Contexts view on the tab system of Talend Studio, go to Window > Show view > Talend, and select Contexts.
The Contexts tab view shows all of the variables that have been defined for each component in the current Job 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.
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 the Contexts tab view and click the [+] button at the upper right corner of the view.
The [Configure Contexts] dialog box pops up. A context named Default has been created and set as the default one by the system.
Select the context Default, click the Edit... button and enter Prod in the [Rename Context] dialog box that opens to rename the context Default to Prod.
Then click OK to close the dialog box.
Click the New... button and enter Test in the [New Context] dialog box. Then click OK to close the dialog box.
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 [Configure Contexts] dialog box.
The newly created contexts are shown in the context variables table of the Contexts tab view.
Click the [+] button at the bottom of the Contexts tab view to add a parameter line in the table.
Click in the Name field and enter the name of the variable you are creating, host in this example.
From the Type list, select the type of the variable corresponding to the component field where it will used, String for the variable host in this example.
If needed, click in the Comment field and enter a comment to describe the variable.
Click in 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 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 steps above to define all the variables in this example.
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:
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.