How to centralize context variables in the Repository

Talend ESB Studio User Guide

EnrichVersion
6.4
EnrichProdName
Talend ESB
task
Design and Development
EnrichPlatform
Talend Studio

Context variables centrally stored in the Repository can be reused across various Jobs.

You can store context variables in the Repository in different ways:

How to create a context group and define context variables in it

The following example will demonstrate how to use the [Create / Edit a context group] wizard to create a context group named TalendDB that contains two contexts named Prod and Test and define a set of variables - host, port, database, username, password, and table_name - under the two contexts in the Repository.

Create the context group and contexts

  1. Right-click the Contexts node in the Repository tree view and select Create context group from the contextual menu.

    A 2-step wizard appears to help you define the various contexts and context parameters.

  2. In Step 1 of 2, type in a name for the context group to be created, TalendDB in this example, and add any general information such as a description if required. The information you provide in the Description field will appear as a tooltip when you move your mouse over the context group in the Repository.

  3. Click Next to go to Step 2 of 2, which allows you to define the various contexts and variables that you need.

    A context named Default has been created and set as the default one by the system.

  4. Click the [+] button at the upper right corner of the wizard to define contexts. The [Configure Contexts] dialog box pops up.

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

  6. Click the New... button and enter Test in the [New Context] dialog box. Then click OK to close the dialog box.

  7. 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 on the wizard.

    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.

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

Define context variables

  1. Click the [+] button at the bottom of the wizard to add a parameter line in the table.

  2. Click in the Name field and enter the name of the variable you are creating, host in this example.

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

  4. If needed, click in the Comment field and enter a comment to describe the variable.

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

    Type

    Value field

    Default value

    String (default type)

    Editable text field

    null

    Boolean

    Drop-down list box with two options: true and false

    Character, Double, Integer, Long, Short, Object, BigDecimal

    Editable text field

    Date

    Editable text field, with a button to open the [Select Date & Time] dialog box.

    File

    Editable text field, with a button to open the [Open] dialog box for file selection.

    Directory

    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.

    (Empty)

    Password

    Editable text field; text entered appears encrypted.

    Warning

    It is recommended that you enclose the values of string type variables between double quotation marks to avoid possible errors during Job execution.

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

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

Once you created and adapted as many context sets as you want, click Finish to validate. The group of contexts thus displays under the Contexts node in the Repository tree view. You can further edit the context group, contexts, and context variables in the wizard by right-clicking the Contexts node and selecting Edit context group from the contextual menu.

How to add a built-in context variable to the Repository

You can save a built-in context variable defined in a Job to a new context group, or an existing context group provided that the context variable does not already exist in the group.

  1. In the Context tab view of a Job, right-click the context variable you want to add to the Repository and select Add to repository context from the contextual menu to open the [Repository Content] dialog box.

  2. In the dialog box, do either of the following:

    • to add your context variable to a new context group, select Create new context group and enter a name for the new context group in the Group Name field, and then click OK.

    • to add your context variable to an existing context group, select the context group and click OK.

    Warning

    When adding a built-in context variable to an existing context group, make sure that the variable does not already exist in the context group.

    In this example, add the built-in context variable password to a new context group named DB_login.

    The context variable is added to the Repository context group of your choice, along with the defined built-in contexts, and it appears as a Repository-stored context variable in the Contexts tab view.

How to create a context from a Metadata

When creating or editing a metadata connection (through a File or DB metadata wizard), you have the possibility to save the connection parameters as context variables in a newly created context group under the Contexts node of the Repository. To do so, complete your connection details and click the Export as context button in the second step of the wizard.

For more information about this feature, see Exporting metadata as context and reusing context parameters to set up a connection.