mangusbrother mangusbrother - 1 year ago 344
Linux Question

Java not finding environment variables defined in Jenkins

I have a snippet of code that is obtaining an environment variable as follows:


locally on my windows machine this works fine.

However, on my Jenkins CI Server which is running CentOS I am encountering some issues

I have tried setting the value of MY_VAL through both the envinject plugin as well as the global jenkins settings

If i do a pre-build step to echo the value out, it works fine, however inside my java code this is not being resolved.

How do I get this to be resolved?

Answer Source

You can achieve that by installing EnvInject plugin.

1) After installing check the Prepare an environment for the job option in the job configuration screen. This option will display several field for you to fill.


2) Fill the Script Content area with a command touch to create the file.

3) Fill the Properties Contentt field with the variables you want to inject inside your recently created file by doing so. Place one variable per line ex:


4) Reference file you've just created in the file path area.

5) At runtime Jenkins will inject those variables and they will be available to your program.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download