Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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!

share|improve this question

1 Answer 1

Read carefully sudo man page SECURITY NOTES.

try -i option that (simulate initial login) option runs the shell specified in the passwd(5) entry of the target user as a login shell. This means that login-specific resource files such as .profile or .login will be read by the shell. If a command is specified, it is passed to the shell for execution. Otherwise, an interactive shell is executed. sudo attempts to change to that user’s home directory before running the shell. It also initializes the environment, leaving DISPLAY and TERM unchanged, setting HOME, SHELL, USER, LOGNAME, and PATH, as well as the contents of /etc/environment on Linux and AIX systems. All other environment variables are removed..

    sudo -u administrator -i "~administrator/BuildAgent/bin/agent.sh start"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.