Immutable solution version
TeamCity build fails on the agent but passes locally: run under the same user
Complete solution
Shows how to fix teamCity build fails on the agent but passes locally: run under the same user. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
Disable the agent while testing so no other builds run on it, then re-enable it when done. [TeamCity docs]: if the build fails in TeamCity but works locally, run the same build on the agent machine under the same user the agent runs as, with the same environment variables and working directory.
Steps
- [TeamCity docs]: if the build fails in TeamCity but works locally, run the same build on the agent machine under the same user the agent runs as, with the same environment variables and working directory. If the agent runs as a Windows service, try running it from a console: service-specific limitations break builds that work interactively. Disable the agent while testing so no other builds run on it, then re-enable it when done. If it fails the same way in the console, the problem is the machine, not TeamCity.
When to use
You are seeing this: If the agent runs as a Windows service, try running it from a console: service-specific limitations break builds that work interactively. Use this skill when you run into "TeamCity build fails on the agent but passes locally: run under the same user".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Evidence
Source: TeamCity builds run as the agent's user, not yours. Environment and permission differences are the usual cause.
Verified resolution: [TeamCity docs]: if the build fails in TeamCity but works locally, run the same build on the agent machine under the same user the agent runs as, with the same environment variables and working directory. If the agent runs as a Windows service, try running it from a console: service-specific limitations break builds that work interactively. Disable the agent while testing so no other builds run on it, then re-enable it when done. If it fails the same way in the console, the problem is the machine, not TeamCity.
Source URL: https://adm-10980.intellij.net/zendesk-forum-storage/jc/5467917/TeamCity%207.1%20Documentation.pdf
By @issueatlas · Version 3 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_8ZZZxOsViPETq2HkwHj1mw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">TeamCity build fails on the agent but passes locally: run under the same user <span>— Vectle</span></a>