44

Where do the environment variables under Jenkins ( manage jenkins -> system information ) come from?

I checked /etc/init.d/tomcat5, /usr/bin/dtomcat5, /usr/bin/tomcat5, /etc/sysconfig/tomcat5 and /etc/profile but do not see any such variables there specially the ones related to Oracle (Base, Home, Ld_lib, path, etc.). Tomcat's bashrc has some oracle related variables which I commented out but I still see the same in the jenkins system info page. Any directions?

Bazer Con
  • 105
  • 4
f-z-N
  • 1,645
  • 4
  • 24
  • 38

3 Answers3

59

The environment variables displayed in Jenkins (Manage Jenkins -> System information) are inherited from the system (i.e. inherited environment variables)

If you run env command in a shell you should see the same environment variables as Jenkins shows.

These variables are either set by the shell/system or by you in ~/.bashrc, ~/.bash_profile.

There are also environment variables set by Jenkins when a job executes, but these are not displayed in the System Information.

jpaugh
  • 6,634
  • 4
  • 38
  • 90
Alex Bitek
  • 6,529
  • 5
  • 47
  • 77
  • 3
    I have set environment variable for the jenkins account as well as root account for the TZ variable in the ~/.bashrc, ~/.bash_profile of both accounts. The env command in both accounbts lists TZ var setting. But Jenkins /systemInfo page does not show TZ and my unit test which relies on it is failing. What could be wrong? – Farrukh Najmi Dec 24 '14 at 13:48
  • @FarrukhNajmi Try setting the environment variable as system wide in [/etc/environment](https://help.ubuntu.com/community/EnvironmentVariables#A.2BAC8-etc.2BAC8-environment) or source the files where you've added your own variables at the beginning of your build script. Also see: https://stackoverflow.com/questions/5818403/jenkins-hudson-environment-variables – Alex Bitek Dec 24 '14 at 14:21
  • 3
    If you're using Jenkins on Windows and it runs as a system service, then make sure the environment variables are set as system wide ones, not per-user, otherwise Jenkins won't be able to see them. – pxb Jun 17 '16 at 13:13
  • Thank you for the Jenkins variables link, do you know if there is another place where it defines more variables? I can't find a variable with the Jenkins user who started the build. Any help appreciated! – Efren Aug 18 '16 at 07:10
  • Apparently it is only available through this plugin: https://wiki.jenkins-ci.org/display/JENKINS/Build+User+Vars+Plugin – Efren Aug 18 '16 at 07:12
  • they aren't in there. – java-addict301 May 13 '19 at 20:42
17

What ultimately worked for me was the following steps:

  1. Configure the Environment Injector Plugin
  2. Goto to the /job/<project>/configure screen
  3. In "Build Environment" section check "Inject environment variables to the build process"
  4. In "Properties Content" specified: TZ=America/New_York
Bazer Con
  • 105
  • 4
Farrukh Najmi
  • 5,055
  • 3
  • 35
  • 54
  • I'm trying to set a variable with a dynamic value. Do you know how to do run a script/batch command in step 4 in order to set the value? – NealR Mar 30 '16 at 12:51
  • 2
    The EnvInject Plugin allows you to prepare the environment using a shell script either by referencing a script file (see Script File Path) or by including its content (see Script Content). I would appreciate an up vote and marking this as the correct answer. Thanks. – Farrukh Najmi Apr 20 '16 at 17:00
  • I did that but how do you access TZ in your bash script? `loc=${TZ}` or `loc=${env.TZ}` doesn't work – Kenan Sep 10 '18 at 17:28
17

The quick and dirty way, you can view the available environment variables from the below link.

http://localhost:8080/env-vars.html/

Just replace localhost with your Jenkins hostname, if its different

vkrams
  • 7,267
  • 17
  • 79
  • 129
  • 2
    The URL mentioned works as expected (copy/paste) directly in the browser address bar, but through the GUI of Jenkins itself, in what section and where is the link that refers to that URL? – Manuel Jordan Sep 02 '21 at 13:48