TeamCity Build Agent won't upgrade
Asked Answered
S

7

20

We are trying to setup a build agent and every time we start it the log shows the following messages:

[2012-09-18 12:52:01,805]   INFO -    jetbrains.buildServer.AGENT - Starting agent shutdown sequence, reason: Restart agent, failed to download upgrade from server 
[2012-09-18 12:52:01,821]   INFO -    jetbrains.buildServer.AGENT - Host configuration for downloading updates: HostConfiguration[host=http://localhost:8000] 
[2012-09-18 12:52:01,821]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/teamcity-agent.xml ==> E:\buildAgent\temp\m8a1mAwTuLIngev3yRUMPUuaYWZFmMSh 
[2012-09-18 12:52:01,849]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/plugins/agentSystemInfo.zip ==> E:\buildAgent\update\plugins\agentSystemInfo.zip 
[2012-09-18 12:52:01,880]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/plugins/amazonEC2.zip ==> E:\buildAgent\update\plugins\amazonEC2.zip 
[2012-09-18 12:52:01,921]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/plugins/ant.zip ==> E:\buildAgent\update\plugins\ant.zip 
[2012-09-18 12:52:02,056]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/plugins/antPlugin.zip ==> E:\buildAgent\update\plugins\antPlugin.zip 
[2012-09-18 12:52:02,078]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/plugins/assembly-info-patcher.zip ==> E:\buildAgent\update\plugins\assembly-info-patcher.zip 
[2012-09-18 12:52:02,098]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/plugins/clearcase-agent.zip ==> E:\buildAgent\update\plugins\clearcase-agent.zip 
[2012-09-18 12:52:02,106]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/plugins/commandLineRunner.jar ==> E:\buildAgent\update\plugins\commandLineRunner.jar 
[2012-09-18 12:52:02,118]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/plugins/coveragePlugin.zip ==> E:\buildAgent\update\plugins\coveragePlugin.zip 
[2012-09-18 12:52:02,151]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/plugins/crashDetector.zip ==> E:\buildAgent\update\plugins\crashDetector.zip 
[2012-09-18 12:52:02,163]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/plugins/cvsAgent.zip ==> E:\buildAgent\update\plugins\cvsAgent.zip 
[2012-09-18 12:52:02,183]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/plugins/dotCover.zip ==> E:\buildAgent\update\plugins\dotCover.zip 
[2012-09-18 12:52:02,308]   INFO -    jetbrains.buildServer.AGENT - Downloading http://localhost:8000/update/plugins/dotNetPlugin.zip ==> E:\buildAgent\update\plugins\dotNetPlugin.zip 
[2012-09-18 12:52:03,830]   INFO - agent.impl.AgentPortFileWriter - Delete agent runtime file from E:\buildAgent\logs\buildAgent.port 
[2012-09-18 12:52:03,831]   INFO -    jetbrains.buildServer.AGENT - Unregistering from build server: 5 

Has anyone seen anything like this before? We've looked at the server logs and aren't seeing anything on them to indicate what could be wrong.

Superpower answered 18/9, 2012 at 18:55 Comment(0)
W
18

I ran into the same issue. Both the build agent and the server are installed on Windows Server 2012.

I stopped the build agent service and deleted the logs from BuildAgent\logs and restarted the build agent service so I could see a fresh log.

upgrade.log showed me that the build agent received a call from the teamcity server to upgrade. The log also showed the following:

"Please check TeamCity build agent service user have enough permissions to stop and start the service."

Using the Local Security Policy, I granted the build agent service user "logon as a service" rights but this is not sufficient to start and stop a service. By default, only members of the Administrators group can start, stop, pause, resume or restart a service. After I added the build agent service user to the Administrator group and restarted the build agent service, the upgrade finished successfully and the agent connected again.

Alternatively, as described by BatteryBackupUnit and https://web.archive.org/web/20171019005501/http://windowsitpro.com/security/letting-user-start-and-stop-services-without-granting-user-administrator-privileges, it's possible to give the TeamCity Windows user account the start, stop and pause permissions on the TeamCity Build Agent service. The article says that something like

subinacl /service spooler /grant=contoso\cortana=top

will suffice.

Or, if you don't want to use a tool that Microsoft no longer makes available, then you can use Process Explorer, as described at https://superuser.com/a/315709/12337.

Weissberg answered 19/8, 2014 at 21:26 Comment(2)
If you don't want to grant the service-user administrative privileges (which you should not, from a security point of perspective), there's another way to just grant specific service start/stop privileges, see hereCostermonger
The error logged in this case would include something along the lines of Failed to stop TeamCity build agent service via net.exe. indicating this would fix the problem, as it did for me. The logs above don't show any symptoms of this specifically.Dwarf
O
12

I had this problem when running the agent with systemd on Ubuntu 18.04. The agent exits with code 143 when upgrading and this is interpreted as an error. It needs to be added to the list of acceptable error codes with SuccessExitStatus=143 0

Here's the full configuration:

[Unit]
Description=TeamCity Build Agent
After=network.target

[Service]
Type=forking
RemainAfterExit=yes
PIDFile=/build-agent/logs/buildAgent.pid
ExecStart=/build-agent/bin/agent.sh start
ExecStop=/build-agent/bin/agent.sh stop
User=build
Group=build

Restart=on-failure
RestartSec=5s

# agent will exit with 143 during upgrade process
SuccessExitStatus=143 0

[Install]
WantedBy=multi-user.target
Oliva answered 5/5, 2019 at 20:16 Comment(0)
B
8

The TeamCity build agent can sometimes take a long time to upgrade. If you believe that the upgrading takes too long with no positive results do as follows:

  1. Uninstall the build agent
  2. Download the build agent pack from your server
  3. Reinstall the agent

Upgrading process should go faster after this. If it does not help it is better to contact JetBrains tech support.

Braces answered 28/9, 2012 at 9:11 Comment(6)
Yeah we ended up doing that. I'm leaving this open until we get a fix from them and then I'll post it since at least one other person seems to be having this problem.Superpower
Did you get a resolution to this?Ary
i'm stuck with the same issue. Resintalling doesnt helpChromonema
Unfortunately we never got an answer to this though the latest answer by Frank seems interesting.Superpower
It's worth pointing out that if you use HTTPS and self-signed certificates that this approach will delete them from the build agent and stop it from working.Machzor
did this but still facing same issueNourish
F
6

A really simple way of doing this if your enterprise security policy doesn't allow you to add users to the 'Administrators' group, but the user your logged on as does have elevated rights. Stop the service running, via the Services.msc and then open a command prompt (with elevated rights) in the agent bin directory and run

agent.bat start

Let the agent update with this user and then once it has finished and you can see it successfully registered in the Teamcity UI. Kill the processes and restart the Service.

Fehr answered 17/1, 2017 at 12:1 Comment(0)
P
4

If you're using a "jailed" build user like we are, you'll see "Please check TeamCity build agent service user have enough permissions to stop and start the service."

There are workarounds but no graceful solution to this. Here's why:

  • Workaround 1: "TCBuildAgent" service needs "jailed" needs start/stop service credential access assigned to it. SubinACL is your best tool for assigning this (lengthy but full discussion).
    • TeamCity removes "TCBuildAgent" and installs a new one, effectively eliminating the service credentials assigned to it. So, you must issue SubinACL grant access commands every time you upgrade. Clumsy and annoying
  • Workaround 2: Aforementioned tip of adding "jailed" to Administrators group is viable and permits a proper upgrade, though violates the concept of a "jailed" user.

After much fiddling with SubinACL, I've thrown in the towel and just temporarily add "jailed" to Administrators group for the upgrade process then remove it afterward.

I trust that Jetbrains isn't gonna do something awful and malicious with TCBuildAgent... not during upgrade, anyway ;)

Pyridoxine answered 31/7, 2015 at 1:27 Comment(0)
B
1

I had a similar problem. helped me to reinstall the antivirus.

http://devnet.jetbrains.com/thread/440728

Bemean answered 4/9, 2013 at 0:26 Comment(0)
P
-1
  1. Stop the agent:

    ./agent.bat stop

  2. Reinstall agent.

  3. Start the agent:

    ./agent.bat start

Pour answered 30/9, 2014 at 13:34 Comment(1)
Killing a process and then restarting a pc.. Why not restarting it directly?Saskatchewan

© 2022 - 2024 — McMap. All rights reserved.