Creating a context group
A context group is a set of (usually) related context variables for use within a project. This recipe shows how to create a new context group.
How to accomplish it…
The steps for creating a context group are as follows:
- Open the metadata panel, and right-click on the context section.
- Select the Create context group
- Name the new group cookbookGeneral.
- Click on the Next button, and you will see the main context variable panel.
- Click on + to add a new variable and type in cookbookDirectory.
- Set the type to the Directory.
- Now, click on the Values as a table tab, and click on the Default column for cookbookDirectory. Click on the …
- This will open a directory navigation window, so navigate to the cookbook data directory, and click on Finish.
How it works…
The context group is created in the metadata panel, and the individual context variables can then be added, along with their default values. Because we chose the type as the Directory, Talend gives us the option of using a windows dialogue to simplify the mechanism for selecting the directory we wish to use.
In this recipe, we have created a basic context, but there are more features that you can explore.
Subscribe to our youtube channel to get new updates..!
The context dialogue allows many different types of context variables to be defined, and in some cases, as in this recipe, it will provide a dialogue to make definition easier.
Prompt for variable values using the tree mode
Updating values in the context group can also be done in the tree mode. This is an alternative method that differs in one important way.
The tree mode provides an option that will prompt for a value to be displayed at runtime, by checking the prompt box for a variable.
The prompt will appear at runtime, as shown in the following screenshot, and is a useful means for providing test values when developing a job:
Adding a context group to your job
A job will not automatically use a CONTEXT GROUP. This exercise shows how to add a context group to a job.
Open the jo_cook_ch06_0010_addContextGroup job.
How to achieve it…
The steps for adding a context group to your job are as follows:
- Open the context panel, and click on the context icon shown as follows:
- You will then be presented with the list of available context groups.
- Select cookbookDB, and then Ok.
- You will now see that the cookbookDB context variables have been added as read-only variables into the job.
How it works…
The context dialogue within a job allows single (in the job) contexts, as well as context groups, to be added to a job.
The preceding method shows how to add all context variables into a job. There is also an option to add only a subset of the variables within the group, if you drill down into the context group when selecting, demonstrated as follows:
Another method of adding the context to the job from the metadata is to drag the context metadata icon in the Contexts panel.