How to pass parameter values from command line in Talen Open Studio

Using parameters with Talend Open Studio

Passing parameters to Talend Open Studio is a common solution to parametrize a job execution. It is an easy task once learned how to use Context parameters in Talend Open Studio.

Talend Open Studio Context

1) First run Talend Open Studio and open or create a project.

Talend Open Studio project creation

2) Then press the right mouse button over Contexts in the Repository tab and select Create context group from the menu. Talend allows to define as many Contexts as you want which can be selected when the application runs. Most of the times, as in this tutorial, only one Context is defined.

Talend Open Studio Context

3) Give a name to the new context, for example "Default", and press Next

Talend Open Studio create context

4) The next window allows to define Context parameters. To add a new parameter press the plus button and give a name to the new item. Its is also possible to define a parameter type and write a mnemonic comment.

Talend Open Studio add parameters

5) Now you can assign a default value for each parameter, so they can be used while executing the job in Talend Open Studio. Just press on "Values as table" tab and assign the default values. In this example ParamA contains "Test!" as default value while ParamB contains "Value!". It's possible to change parameters values at any time, using the Talend Open Studio wizard (Right click on Context item -> Edit Context group ->Next) or setting parameter directly at runtime (we'll see how to do that in the next paragraph).

Talend Open Studio edit parameters

Press Finish to close the wizard and apply the changes.

Using Context parameters in a Talend Job

Talend Open Studio is now ready to assign Context parameters to a Job. For this example we create a new Job (Job Designs -> right click -> Create job). Then select the Contexts tab and click on the button pointed by the cursor in this picture.

Talend Open Studio apply context

In the form that appears you can select which parameters will be made avilable to the job. This is a necessary step to propagate parameter values, for example select all the items.

Talend Open Studio select variables

Only the context variables which are selected are passed to the Talend job. These context variables can be used in several components, for example in query and datasource components to parametrize db connections and query executions. To apply a parameter to a component field simply press Ctrl+Space. Talend will list which parameters are available for the current job.

For example put a tWarn component from the Palette on the Job editor. Then use a tLogCatcher and link it to a new tLogRow component (right click on tLogCatcher -> Row -> Main and point the cursor to tLogRow).

Now select tWarn component and choose the Component tab. As you can see in the picture you can fill component values with parameters and the Ctrl+Space key helps a lot on this task.

Talend Open Studio assign parameter to a component


During run time parameters will be replaced with values which are defined by default or set in the command line. This is very usefull when you need to parametrize database connections or procedures execution.

Assign parameteres values in command line

Parameters are very usefull when you compile your Talend Job and make it executable. To compile a job in Talend Open Studio simply right click on the job name and select Export Job Scripts.

Talend Open Studio export job scripts

In the next form make sure the Context scripts field is checked and choose a path where the archive will be saved ("To archive file" form field).

Talend Open Studio export job settings

Talend compiles the job in a Java application. To run the application first extract the archive created by Export job scripts procedure and then run the command JobTest/JobTest_run.bat (or in Linux).

Parameters can be set at a runtime with the --context_param command line switch. For example with the command:

JobTest_run.bat --context_param ParamA=ValueA --context_param ParamB=ValueB

You can also edit JobTest_run.bat and set the parameter value directly into the script:

java -Xms256M -Xmx1024M -cp classpath.jar; test2.jobtest_0_1.JobTest --context=Default
--context_param ParamA=ValueA --context_param ParamB=ValueB


Passing parameters to sub-jobs

In structured applications a Job can call another Job and it's necessary to transmit parameters to sub-jobs. In Talend Open Studio this task is easy. When you create a sub job (that is a job who calls another job) simply click its Component tab and make sure Transmit whole context is checked.

Talend Open Studio Transmit parameters sub jobs


Next time you run or compile the main Job all parameter values will be transmitted to the sub Jobs.