One Star

[resolved] passing context from command line to sub jobs

Hi ,
I want to pass the context variables from command line to job and its sub jobs.
Please find the job design as below:
Job 1 -- trunjob(will trigger second job Job 2) -- >Job 2 -- trunjob(will trigger third job Job 3) --- > Job 3;
(I have checked the check box present in trunjob as transmit whole context.. still it is not working..)
I want to pass the context variables to all Job 1, Job 2 , Job 3 through the command line.
can anyone tell me how do i achieve the same.
I have used the below syntax but it is not working.
Job 1.bat --context_param db_database=xyz --context_param db_host=abc --context_param db_username=user
all these context variables are present in all the three jobs.
first job is getting executed properly but for the second job it is giving me error that db_host is null..?
Thanking you,
with kind regards,
Akash Sonawane.
1 ACCEPTED SOLUTION

Accepted Solutions
One Star

Re: [resolved] passing context from command line to sub jobs

Hello Shong and Willm,
would like to thank you for your quick reply.
I got the solutions and the solutions is I am using the globalMap.get("DB_Host") in the context tab in value field of DB_Host parameter so like wise i am storing all the context variables value and now they getting passed to next subjobs.
Thank you again for your valuable time.
Thanking you,
with kind regards,
Akash Sonawane
5 REPLIES
Four Stars

Re: [resolved] passing context from command line to sub jobs

Hi Akash,
As per your explanation if things are working as expected, then it is weird that context parameter loaded by parent jobs through command line are not passed through the parent job to subjob.
But, as a standard practice, in Main Job, load context parameters through property file and using tContextLoad component make it available to all the subJobs (provided you enable the check box for transmit whole context)
https://help.talend.com/search/all?query=tContextLoad&content-lang=en
Someone from talend would come up with the answer else you can create a bug on this.
Thanks
Vaibhav
One Star

Re: [resolved] passing context from command line to sub jobs

akashsonawane - seems like you're doing everything Ok.
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
What I'd do next is to print the values using System.out.println in tJavas in all jobs - of the contexts that are not getting loaded properly. That should point out where you have hiccups in your job.
Community Manager

Re: [resolved] passing context from command line to sub jobs

Hi
- Make sure the 'transmit the whole context' option on tRunJob is checked.
- The child jobs have the same context and the same variables as parent job, for example, db_host both exist in parent job and child job.
- Specify a new value to context variable when executing the job script from command prompt, for example
D:\file\SpecifyContextVariableDemo_0.1\SpecifyContextVariableDemo>jobName.bat --context=Default --context_param nb_line=3 --context_param name=Talend3

Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] passing context from command line to sub jobs

Hello Shong and Willm,
would like to thank you for your quick reply.
I got the solutions and the solutions is I am using the globalMap.get("DB_Host") in the context tab in value field of DB_Host parameter so like wise i am storing all the context variables value and now they getting passed to next subjobs.
Thank you again for your valuable time.
Thanking you,
with kind regards,
Akash Sonawane
One Star

Re: [resolved] passing context from command line to sub jobs

You're most welcome...