1

We have some TeamCity build agents running and I'd like to destroy and rebuild all agents over night automatically to have a clean set of agents in the morning. Destroying and provisioning the agent isn't a problem but I can't find a way to authorize the fresh agents automatically. The TeamCity documentation talks about the web UI only which is a pretty bad starting point for automation.

Anyone got a solution for this?

5 Answers 5

1

I'm trying to do exactly that, and from what I understood, we need our provisioning system to maintain the file at <build_agent_work_dir>/conf/buildAgent.properties with the same content across restarts.

Reference: https://confluence.jetbrains.com/display/TCD9/Build+Agent+Configuration

1

Teamcity does not provide automatic agent authorization other than UI but if you are using same server/host names you can try by backing-up and restoring of agent.properties file as specified by Marcel. this file will have the authorization key of the agent

as rightly pointed, documentation link has just UI level authorization, no CLI or plugins and is hard way to do it in bulk

from Documentation:

they are authorized in the TeamCity web UI.

The agent running on the same computer as the server is authorized by default.

1

You can use the official plugin for this purpose https://confluence.jetbrains.com/display/TW/Agent+Custom+Token+Authorize+Plugin

Unfortunately, it allows only one agent per token, but that is a good point to start. There are also unofficial plugins like https://github.com/matt-richardson/TeamCityAgentAutoRegisterPlugin that allow automatic authorization of more the one agent per token

1

This should get new agent authorized via TC API

curl -u teamcityuser:userpassword --request PUT --data true --header "Content-Type: text/plain" http://teamcityserver/httpAuth/app/rest/agents/mynewteamcityagent/authorized
1

Yes, your agent servers just need to create the buildAgent.properties file with a unique, but procedurally-generated auth token, for example:

TOKEN=$(md5sum <<< $(hostname -f) | cut -d ' ' -f 1)

cat <<-EOF > /opt/buildAgent/conf/buildAgent.properties
serverUrl=https://myteamcityserver.corp
name=$(hostname -f)
workDir=../work
tempDir=../temp
systemDir=../system
authorizationToken=${TOKEN}
EOF

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .