TeamCity agent's show a list of "Environment Variables" under Agent Parameters but I cannot get them to update. I've added environment variables to my agent operating system, but cannot get them to refresh. I've tried restarting the agent and disabling and re-enabling the agent.
Asked
Active
Viewed 3.1k times
2 Answers
40
The TeamCity agent doesn't actually read environment variables from the OS. Instead it reads them from the buildAgent/conf/buildAgent.properties
file on your agent machine. Down at the bottom of this file you'll see instructions on how to add new variables. Something like this:
# Environment Variables
#env.exampleEnvVar=example Env Value
env.GRADLE_HOME=/Frameworks/gradle-2.9
Once you've done this, switch to the command prompt on your agent machine, and execute something like this:
./agent.sh stop
./agent.sh start
Obviously OS dependent. There is a .bat
file there for Windows.
That should get your environment variables showing up in TeamCity.
8
Just tried it in TeamCity 2017.2.1 and the machine-level environment variables are picked up by TeamCity build agents (as well as the ones in buildAgent.properties), so it looks like this has been fixed.

EM0
- 5,369
- 7
- 51
- 85
-
2I will say this didn't seem to be the case on a Linux build agent (version 2018.2.4). Maybe OS specific – Craig Brett Jul 24 '19 at 15:04
-
1certainly isn't the case for me on Windows build agents... (2020.1.4) – stuzor Sep 17 '20 at 00:11