I have created a java program to do a ssh connection and do a file transfer using scp. I have added username, hostname and password as environment variables in jenkins. I need to access the value of these environment variables inside my java program.
I tried using the below options inside my java file, but it did not work.
System.getProperty("HOSTNAME");
System.getenv("HOSTNAME");
I cannot use EnvironmentInjectorPlugin due to some security issues. Could you please point me in the right direction.
I got this to work by passing the parameters from the Build Step > Maven > Goals and Options,
Maven: Goals and Options
-DHOSTNAME=${HOSTNAME} -DUSERNAME=${USERNAME} -DPASSWORD=${PASSWORD} -q clean install test
and retrieved the value from java file as
String strUserName = System.getProperty("USERNAME");
The value inside ${' '} is actually environmental variables declared in jenkins config.