I defined several environment variables in /etc/environment, but a process (build started by TeamCity) cannot see their values. I don't know what I'm doing wrong here.. this is the content of my /etc/environment file:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
CATALINA_BASE="/var/lib/tomcat7"
CATALINA_HOME="/usr/share/tomcat7"
ACTIVEMQ_HOME="var/lib/activemq"
ACTIVEMQ_BASE="var/lib/activemq"
ACTIVEMQ_CONF="var/lib/activemq/conf"
ACTIVEMQ_DATA="var/lib/activemq/data"
ACTIVEMQ_OPTS_MEMORY="-Xms128m -Xmx192m"
M2_HOME="/usr/share/maven3"
MAVEN_HOME="/usr/share/maven3"
JAVA_HOME="/usr/lib/jvm/java-8-oracle"
The build started by TeamCity uses a Maven runner, and which at some point kicks an Ant build. Since the build was failing, I used Ant to print all environment variables in the system:
<!-- Provides all environment variables as Ant properties prefixed by "env.".
For example, CLASSPATH would be accessible in Ant as ${env.CLASSPATH} -->
<property environment="env"/>
<echo>List of all Environment Variables found in the system:</echo>
<echoproperties>
<propertyset>
<propertyref prefix="env."/>
</propertyset>
</echoproperties>
Sure enough, the ones I set in /etc/environment don't show up.
The build agent running this is started using Ubuntu's Startup app's, where I configured it to run the command:
sudo -H -u administrator /bin/bash --login -c "~administrator/BuildAgent/bin/agent.sh start"
Could it be that this line runs before /etc/environment are set?
If I do a echo $CATALINA_HOME
I see the value properly set, but the build for some reason cannot see it…
NOTE: Although I know it is the wrong way of doing it, I also tried adding export
to the declarations inside /etc/environment
, without any success. Then I removed it.
NOTE 2: I rebooted the machine after making changes to /etc/environment file, of course.
I'm on 14.04 LTS Server with minimal desktop installed (ubuntu-desktop –no–install-recommends) plus a few extras.
Any help is appreciated, thank you!
Best Answer
Read carefully sudoers man page Command environment section.
try -i option: if sudo's -i option (initial login) is specified, sudoers will initialize the environment regardless of the value of env_reset. The DISPLAY, PATH and TERM variables remain unchanged; HOME, MAIL, SHELL, USER, and LOGNAME are set based on the target user. On AIX (and Linux systems without PAM), the contents of /etc/environment are also included. All other environment variables are removed..
If you are using PAM authentication, here is a useful link: Difference between /etc/security/pam_env.conf and /etc/environment + making sudo read pam_env.conf