Where does a TeamCity build agent get its path environment from?
Asked Answered
C

5

44

I'm trying to set up TeamCity to build my project, but my psake buildscript fails, with the reason being narrowed down to its inability to find the git executable, which is supposed to be on the path. When I start a PowerShell and execute the thing by myself, everything works fine.

The content of the Path environment variable (as shown in the System variables list in the windows Environment Variables dialog, as well as the registry at HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment\Path) is

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;c:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;c:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files (x86)\Git\cmd

yet TeamCity says its env.Path is just

C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;c:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;C:\Windows\System32\WindowsPowerShell\v1.0

I have restarted the computer (multiple times) which does not help whatsoever.

Why is the TeamCity build agent's PATH variable different from the system default, and how can I fix it?

Ciaphus answered 11/1, 2012 at 22:32 Comment(2)
I hate to guess, but if you are running it as a windows service, the environment would come from the user running the service.Valletta
No, no solution. I ditched TeamCity and now use CruiseControl.net instead.Ciaphus
Q
25

You can expand the path for a build agent by adding a build parameter named "env.PATH" with the following value on Mac OS and Linux.

%env.PATH%:/my/path

On Windows use ";" instead of ":" as the path delimiter.

You can also add the following to conf/buildAgent.properties in your build agent installation directory.

env.PATH=%env.PATH%:/my/path

(There is a comment at the bottom of the file that shows how to set environment vars.)

Quinn answered 14/5, 2015 at 21:0 Comment(2)
Be warned: I think env.PATH=%env.PATH%:/my/path will resolve to the literal "%env.PATH%:/my/path" unless %env.PATH% had already been previously defined in TC. But %env.PATH% is not the same as trying to append to your existing path using %PATH%;... . To do that you might need to use %%PATH%% so that the percentages are escaped...Ostap
I just tried this, and found that Schneider's comment is wrong, and mockaroodev's approach works.Minimum
K
22

I ran into this same issue and only needed to restart the Team City Build Agent Service to pick up changes to the PATH variable.

Kesha answered 8/2, 2014 at 6:8 Comment(1)
Same here. Using 8.0.5 and had to restart the agents to get the changes picked up.Overplus
M
10

Some previous answers are correct, but are lacking details (and take me some time to really understand them) — Where the Default Agent takes its environment variables is not clear to me: so here is a way to clearly fix them in the agent configuration.

Editing the TeamCity/buildAgent/conf/buildAgent.properties file with env.PATH=/usr/whatever will do the trick. The documentation has a small hint on that.

Once, you've edited that file, you can check in the UI, in Agents > Default Agent > Agent Parameters > Environment Variables that they've been updated (careful, thought, those variables are only refreshed in the UI when the agent is connected; if it's disconnected, the UI displays the previous values).

Muco answered 26/8, 2015 at 9:43 Comment(0)
V
4

The solution is in Build Configuration/6 Build Parameters where you can override env.[ANYTHING] variables.

P.S. Sry to hear that. I'm still determined to succeed with TeamCity.

Valletta answered 21/2, 2012 at 11:12 Comment(0)
A
4

My solution, hinted at by tishma's comment, was to modify the Path environment variable for the User and restart the Team City Build Agent Service

Edit: This bug has been fixed as of TeamCity 7.1

Aesop answered 7/8, 2012 at 16:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.