Five Stars

Loading context values from file

Team, I have a list of jobs where i will be reading a file from source path and do transformation and write in to target path. Now the source path and target path keeps changing for each environment (Development, Test, UAT, Production). So i need to maintain a file in each environment server and access to same to resolve me context value(source and target path). Any help on how to approach this design will be appreciated. If we can build a process that will be common for all the jobs to use will be very helpful. I saw some examples using tcontextload but not sure how to use as I'm new to Talend tool.
  • Data Integration
4 REPLIES
Nine Stars TRF
Nine Stars

Re: Loading context values from file

The better (I think so), define ContextFile as a context variable with the appropriate value depending on the context (Development, Test, UAT, Production).

For each concerned job, go to the job tab, then Extr, uncheck the option "Use Project Settings", check the option "Implicit tContextLoad", choose "From File", set the "From File" field as "context.ContextFile" and set the "Field Separator" field as "==" (for example).

 

Capture.PNG

Finally, define your key/values context files using "==" as a separator.

That's all.


TRF
Employee

Re: Loading context values from file

As @TRF says.  I will add that instead of a context variable, the path to the config path can be a system environment variable.  And you use System.getenv("some variable name").

 

This way you know when your config are by querying the environment variable you defined.  

 

Five Stars

Re: Loading context values from file

Hi iburtally, One more clarification, to access the environment variable, My sample path are something like below, DEV Env : /home/users/DEV/ Test Env : /home/users/TEST/ PROD Env : /home/users/PROD/ In the Job tab, under “Stats & Logs”, the file path option is available, so to access the file path we need give something like below in File path, or do we need to use tJava to access the environment variable, File Path : “/home/users/”+System.getenv("ENV_NAME")+”/” In the above statement ENV_NAME is my parameter that is exported in Unix environment.
Employee

Re: Loading context values from file

That looks fine to me.  Is it working?