Registering agent to TeamCity 2018.1.3 from teamcity-agent docker image fails with 404 when requesting protocols on server

I run the TeamCity 2018.1.3 server from the latest docker image, which I start as follows: 

 

sudo docker run -d --name teamcity-app \
  -v /mnt/teamcity/datadir:/data/teamcity_server/datadir \
  -v /mnt/teamcity/logs:/opt/teamcity/logs \
  -p 8111:8111 \
  --restart=unless-stopped \
  --network atomicbits-net \
  jetbrains/teamcity-server

 

The docker container uses a docker overlay network over which it successfully connects to a postgres DB (also ran in a docker container). In TeamCity the DB is configured properly and the admin user can login successfully. The docker agent is started as follows:

 

sudo docker run -d \
  --name teamcity-agent1 \
  --privileged \
  -e SERVER_URL=teamcity-app:8111 \
  -e DOCKER_IN_DOCKER=start \
  -e AGENT_NAME=agent1 \
  -v /mnt/teamcity/teamcity_agent/conf:/data/teamcity_agent/conf \
  -v agent1_volumes:/var/lib/docker \
  --restart=unless-stopped \
  --network atomicbits-net \
  jetbrains/teamcity-agent

 

The agent starts successfully (see logs below) and it can connect to the 'teamcity-app' host over the overlay network, but when requesting the protocols, a 404 is returned from the teamcity server (see below). In TeamCity, the agent never appears under the Unauthorized agents tab.

 

$ docker logs teamcity-agent1 

/run-services.sh
/services/run-docker.sh
* Starting Docker: docker
...done.
Docker daemon started
/run-agent.sh
File buildAgent.properties was found in /data/teamcity_agent/conf
run agent.sh configure --server-url teamcity-app:8111 --name agent1
Java executable is found: '/usr/lib/jvm/oracle-jdk/jre/bin/java'
Configuring TeamCity build agent...
File buildAgent.properties was updated
Starting TeamCity build agent...
Java executable is found: '/usr/lib/jvm/oracle-jdk/jre/bin/java'
Starting TeamCity Build Agent Launcher...
Agent home directory is /opt/buildagent
Agent Launcher Java runtime version is 1.8
Lock file: /opt/buildagent/logs/buildAgent.properties.lock
Using no lock
Done [1391], see log at /opt/buildagent/logs/teamcity-agent.log
....

[2018-11-03 11:54:53,457] INFO - s.buildServer.agent.AgentMain2 - ===========================================================
[2018-11-03 11:54:53,473] INFO - s.buildServer.agent.AgentMain2 - TeamCity Build Agent 2018.1.3 (build 58658)
[2018-11-03 11:54:53,480] INFO - s.buildServer.agent.AgentMain2 - OS: Linux, version 4.15.0-1025-aws, amd64, Current user: root, Time zone: UTC
[2018-11-03 11:54:53,481] INFO - s.buildServer.agent.AgentMain2 - Java: 1.8.0_161, Java HotSpot(TM) 64-Bit Server VM (25.161-b12, mixed mode), Java(TM) SE Runtime Environment (1.8.0_161-b12), Oracle Corporation; JVM parameters: -ea -Xmx384m -Dteamcity_logs=../logs/
[2018-11-03 11:54:53,481] INFO - s.buildServer.agent.AgentMain2 - Starting...
[2018-11-03 11:54:53,534] INFO - buildServer.agent.AgentMain2$2 - Refreshing jetbrains.buildServer.agent.AgentMain2$2@6321e813: startup date [Sat Nov 03 11:54:53 UTC 2018]; root of context hierarchy
[2018-11-03 11:54:55,534] INFO - jetbrains.buildServer.AGENT - Calculating CPU benchmark index...
[2018-11-03 11:55:01,169] INFO - jetbrains.buildServer.AGENT - CPU benchmark index is set to 572
[2018-11-03 11:55:01,259] INFO - jetbrains.buildServer.AGENT - Agent tools download temp directory created on path /opt/buildagent/temp/tools
[2018-11-03 11:55:01,434] INFO - dAgentConfigurationInitializer - Loading build agent configuration from /data/teamcity_agent/conf/buildAgent.properties
[2018-11-03 11:55:01,469] INFO - s.buildServer.agent.AgentMain2 - Working dir: /opt/buildagent/work
[2018-11-03 11:55:01,469] INFO - s.buildServer.agent.AgentMain2 - Temp dir: /opt/buildagent/temp
[2018-11-03 11:55:01,471] INFO - rver.plugins.PluginManagerImpl - ===========================================================
[2018-11-03 11:55:01,471] INFO - rver.plugins.PluginManagerImpl - Plugins initialization started...
[2018-11-03 11:55:01,473] INFO - rver.plugins.PluginManagerImpl - Scanning plugins folders
[2018-11-03 11:55:01,474] INFO - .plugins.files.JarSearcherBase - Scanning plugin folder: /opt/buildagent/plugins
[2018-11-03 11:55:01,476] INFO - .plugins.files.JarSearcherBase - Scanning plugin folder: /opt/buildagent/tools
[2018-11-03 11:55:01,491] INFO - rver.plugins.PluginManagerImpl - Found 1 non bundled plugins: [amazonEC2]
[2018-11-03 11:55:01,491] INFO - rver.plugins.PluginManagerImpl - Found 0 bundled plugins: []
[2018-11-03 11:55:01,493] INFO - rver.plugins.PluginsCollection - Load shared classloader for 1 plugins [amazonEC2]
[2018-11-03 11:55:01,500] INFO - rver.plugins.PluginsCollection - No plugins were loaded with standalone classloaders
[2018-11-03 11:55:01,746] INFO - rver.plugins.PluginManagerImpl - Plugins initialization completed (1 plugins loaded): [amazonEC2]
[2018-11-03 11:55:01,747] INFO - rver.plugins.PluginManagerImpl - ===========================================================
[2018-11-03 11:55:01,750] INFO - jetbrains.buildServer.AGENT - Build Agent version: 58658, plugins signature: NA
[2018-11-03 11:55:01,776] INFO - dAgentConfigurationInitializer - Loading build agent configuration from /data/teamcity_agent/conf/buildAgent.properties
[2018-11-03 11:55:01,974] INFO - .agent.AmazonPropertiesUpdater - Fetched AmazonEC2 instance metadata: ami-id=ami-00035f41c82244dab
ami-launch-index=0
ami-manifest-path=(unknown)
instance-id=i-09813e38d2ed4299e
instance-type=t3.small
local-hostname=ip-172-31-33-139.eu-west-1.compute.internal
local-ipv4=172.31.33.139
public-hostname=ec2-34-250-13-150.eu-west-1.compute.amazonaws.com
public-ipv4=34.250.13.150
reservation-id=r-0d80dc89c9e021d43

[2018-11-03 11:55:01,980] INFO - .agent.AmazonPropertiesUpdater - Failed to fetch TeamCity custom instance metadata. Was agent started by TeamCity?
[2018-11-03 11:55:02,007] INFO - .agent.impl.OsArchBitsDetector - Detecting via "getconf LONG_BIT", exit code: 0, output: 64
[2018-11-03 11:55:02,008] INFO - .agent.impl.OsArchBitsDetector - "teamcity.agent.os.arch.bits" detected as "64"
[2018-11-03 11:55:02,012] INFO - jetbrains.buildServer.AGENT - Start build agent
[2018-11-03 11:55:02,022] INFO - jetbrains.buildServer.AGENT - Agent Web server started on port 9090
[2018-11-03 11:55:02,031] INFO - buildServer.AGENT.registration - Registering on server via URL "http://teamcity-app:8111": AgentDetails{Name='agent1', AgentId=null, BuildId=null, AgentOwnAddress='null', AlternativeAddresses=[10.0.0.50, 172.18.0.4, 172.18.0.1, 34.250.13.150], Port=9090, Version='58658', PluginsVersion='NA', AvailableRunners=[], AvailableVcs=[], AuthorizationToken='', PingCode='Mb6O2dPUf6zZK3tReNzSO98k1pn6oQyh'}
[2018-11-03 11:55:02,038] INFO - agent.impl.AgentPortFileWriter - Writing agent runtime file to /opt/buildagent/logs/buildAgent.xmlRpcPort
[2018-11-03 11:55:02,038] INFO - agent.impl.AgentPortFileWriter - Launcher version is 58658
[2018-11-03 11:55:02,039] INFO - agent.impl.AgentPortFileWriter - Writing agent runtime file to /opt/buildagent/logs/buildAgent.xmlRpcPort :DONE!
[2018-11-03 11:55:02,039] INFO - jetbrains.buildServer.AGENT - Build agent started
[2018-11-03 11:55:02,048] WARN - buildServer.AGENT.registration - Error asking server for the protocols via URL http://teamcity-app:8111/app/agents/protocols. Will try later. Details: unexpected response status code 404
[2018-11-03 11:55:02,048] WARN - buildServer.AGENT.registration - Error registering on the server via URL http://teamcity-app:8111. Will continue repeating connection attempts.

 

When requesting the same URL using wget from another docker container (that has wget installed) gives: 

$ docker exec -it alpine1 wget http://teamcity-app:8111/app/agents/protocols
Connecting to teamcity-app:8111 (10.0.0.33:8111)
wget: server returned error: HTTP/1.1 404

 

When I access the same URL from my browser where I have TeamCity cookies set (I'm logged in in my TeamCity server), I get a proper response: 

GET https://<hidden-company-name>/teamcity/app/agents/protocols

<list><string>polling</string></list>

 

Is it possible that there is an authentication problem when the agent first connects to TeamCity? 

 

 

 

 

 

0
3 comments

Hi,

 

This error is pretty strange. May I ask you to send the teamcity-server.log and teamcity-agent.log using the "submit a request" button above?

0
Avatar
Permanently deleted user

It was solved thanks to TeamCity's quick support. I had changed the application's context root on the Tomcat server to /teamcity, so I also had to add this context to the agent configuration, like:  -e SERVER_URL=http://teamcity-app:8111/teamcity 

Thanks!

 

0
Avatar
Permanently deleted user

Had a similar issue.  The agent installer didn't object to a http URL, but it was necessary to change it to https as required by the server.

 

Config file: buildAgent.properties

Property:  serverUrl

 

 

0

Please sign in to leave a comment.