Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
WSyahirah21
Creator
Creator

Setting up the global environment variable for the whole job

I am currently trying to create a nee job using Talend Studio. This job requires me to set system environment variable for the whole job, instead of set it per component.

My job is:

0695b00000N2UIGAA3.png

So as shown in image below, i managed to set the environment variable in tSystem, but how do i make it so that the environment variable is able to be used for the whole job instead of only one single component in TOS?

Labels (4)
1 Reply
gjeremy1617088143

Hi, if you really want to set an environnement variable for all the job you can create a routine :

 

 

package routines;

import java.util.Map;

 

public class MyRoutine {

 

  @SuppressWarnings("unchecked")

public static Map<String, String> getModifiableEnvironment() throws Exception

 

  {

 

  Class<?> pe = Class.forName("java.lang.ProcessEnvironment");

 

  java.lang.reflect.Method getenv = pe.getDeclaredMethod("getenv", String.class);

 

  getenv.setAccessible(true);

 

  java.lang.reflect.Field props = pe.getDeclaredField("theCaseInsensitiveEnvironment");

 

  props.setAccessible(true);

 

  return (Map<String, String>) props.get(null);

 

  }

}

 

 

 

 

then you can call it and add the env var you want like this :

MyRoutine.getModifiableEnvironment().put("propName", "propValue");

 

 !! you will see the folowing warning in the console :

 

WARNING: An illegal reflective access operation has occurred

WARNING: Illegal reflective access by routines.MyRoutine (file:/C:/Users/workspace/LOCAL_PROJECT/poms/code/routines/target/classes/) to method java.lang.ProcessEnvironment.getenv(java.lang.String)

WARNING: Please consider reporting this to the maintainers of routines.MyRoutine

WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations

WARNING: All illegal access operations will be denied in a future release

 

as you can see it's note the best recommended method but it work.

 

if you do System.out.println(System.getenv("propName"));

it will print propValue.

 

else if you just want to stock a key value use tSetglobalVar component.