Using context variables in Talend Studio - 8.0

Version
8.0
Language
English (United States)
Product
Talend Big Data
Talend Big Data Platform
Talend Data Fabric
Talend Data Integration
Talend Data Management Platform
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for Big Data
Talend Open Studio for Data Integration
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
Module
Talend Studio
Content
Design and Development > Designing Jobs

Using context variables in Talend Studio

In this tutorial, discover how context variables can help run the same Talend Job in different environments, and learn how to use them.

Creating a Talend Studio project

Creating a project is the first step to using Talend Studio. Projects allow you to better organize your work.

Procedure

  1. Select Create a new project.
  2. Enter a name for your project.

    Example

    TalendDemo
  3. Click Create.
  4. Click Finish.

Results

Your project opens. You are ready to work in Talend Studio.

Creating a context group

Context groups contain values which change according to the context (prod or staging for example) in which you run a Job.

Procedure

  1. In the Repository, right-click Contexts and click Create context group.
  2. In the Name field, enter a name.

    Example

    databasePropertyType
  3. Optional: In the Purpose field, enter a purpose.

    Example

    Fetching context from a database
  4. Optional: In the Description field, enter a description.

    Example

    Setting up context variables for different situations
    Tip: Enter a Purpose and Description to stay organized.
  5. Click the plus button to add a context value.
    1. In the Name field, enter a name.

      Example

      1. host
      2. port
      3. database
      4. username
      5. password
    2. Select the Type property of your context value.

      Example

      1. For host, select Directory.
      2. For port, select Integer.
      3. For password, select Password.
    3. Enter the Value property of your context value.

      Example

      1. For host, enter 127.0.0.1.
      2. For port, enter 3306.
      3. For database, enter csv_db 6.
      4. For username, enter root.
  6. Click Finish.

Results

The new context group, databasePropertyType 0.1, displays under Contexts in the Repository.

Adding values to a context group and running a Job accordingly

You can use context groups to run Jobs according to different predetermined parameters. By taking the example of deployment environments, you can configure passwords or usernames following a Job execution on your production or staging environment.

Before you begin

You must have created a context group (see Creating a context group).

Procedure

  1. In the Repository, expand Contexts, right-click a context group and click Edit context group.
  2. Click Next.
    You are brought to Step 2 in the wizard.
  3. Click Configure Contexts...
  4. Click New...
  5. Enter a context name.

    Example

    prod
  6. Click OK.
    You are brought back to the Configure Contexts window.
  7. Define your context parameters.

    Example

    Link your context to a database.
  8. Optional: Select the Default context environment.
  9. Click Finish.
  10. In the Run view, select a Context.
  11. Click Run.

Results

You have configured a context group for your different deployment environments.

Exporting a metadata definition as a context group

You can export metadata definitions as context groups to use their parameters on a Job level, rather than a component level.

Before you begin

You must have created a metadata definition (see Creating a metadata definition).

Procedure

  1. In the Repository, expand Metadata > File delimited, right-click the file delimited metadata of your choice and click Edit file delimited.
  2. The metadata has already been set up, click Next twice.
    You are brought to Step 3 in the wizard.
  3. Click Export as context.
  4. Select Create a new repository context.
  5. Click Next.
  6. In the Name field, enter a name.

    Example

    moviesContextGroup
  7. Optional: In the Purpose field, enter a purpose.

    Example

    Reusing my movie metadata as context
  8. Optional: In the Description field, enter a description.

    Example

    File delimited metadata as a context group
    Tip: Enter a Purpose and Description to stay organized.
  9. Click Next.
    All parameters have been changed to variables with the default values.
  10. Click Finish
    You are brought back to the Edit an existing Delimited file window.
  11. Click Finish.
    1. Optional: Select if you want to propagate the modifications to all Jobs.
    2. Optional: Select the items you want to update.
    3. Optional: Click OK.
    4. Optional: Select if you want to add the context parameters to Jobs using this connection.

Results

In the Component view of the movies component, you may see that all the default property values have been replaced by context variables.

Importing a context group into a Job

You can import a context group into a preexisting Job to standardize the use of your environments. You can configure an access to your staging and production environments, for example.

Procedure

  1. In the Contexts view, click the Import Context button at the bottom of the screen.
    The Select Context Variables window appears.
  2. Select individual variables or groups of variables.

    Example

    Context: databasePropertyType
    Tip: You can access the imported variables by using the prefix context. followed by the variable name (for example: context.database).

Results

You have imported the variables into the Job along with their values.