构建代理可以通过调整 <TeamCity Agent Home>/conf/buildAgent.properties 文件中的设置来配置。
通用代理配置
这个 Java 属性配置文件可以存储将在服务器上发布为 代理属性的属性,并可以参与 代理要求表达式。 所有在文件中定义的 系统和环境属性都将传递给在 agent 上运行的每个构建。
语法参考:
示例代理配置文件:
## The address of the TeamCity server. The same as is used to open the TeamCity web interface in the browser.
## Must include the protocol specification (https:// is recommended).
serverUrl=http://localhost:8111/
## The unique name of the agent used to identify this agent on the TeamCity server
## Use blank name to let server generate it.
## By default, this name would be created from the build agent's host name
name=Default agent
## Container directory to create default checkout directories for the build configurations.
workDir=../work
## Container directory for the temporary directories.
## Please note that the directory may be cleaned between the builds.
tempDir=../temp
## Container directory for agent state files and caches.
## TeamCity agent assumes ownership of the directory and can delete the content inside.
systemDir=../system
######################################
# Optional Agent Properties #
######################################
## A token which is used to identify this agent on the TeamCity server for agent authorization purposes.
## It is automatically generated and saved back on the first agent connection to the server.
authorizationToken=1234567890abcdefghijklml
确保构建代理进程本身可以写入该文件。 例如,该文件已经更新,以存储在服务器端生成的授权令牌。
如果您安装了多个 TeamCity 节点 在反向代理后, serverUrl 应设为代理 URL。
如果 名称 属性未被指定,服务器将会自动生成构建代理名称。 默认情况下,此名称将从构建代理的主机名创建。
当代理运行时,可以编辑该文件:代理检测到更改,并在(如果有)完成运行的构建后自动重启,加载新的设置。
可选属性
构建代理端口
TeamCity 代理以单向模式工作:它们发起与服务器的所有连接,而不是相反。 一旦连接,代理会定期轮询服务器以获取新命令,例如处理排队的构建。 由于服务器不会建立任何传入连接,因此配置代理机器时无需设置任何开放端口。
在少数情况下,代理会运行与同一台机器上其他与构建相关的进程共享数据的进程。 这主要适用于运行较旧的构建步骤和插件。 在这些情况下,代理使用 localhost 端口 9090 来共享这些数据。 您可以在 buildAgent.properties 文件中重新定义此端口:
ownPort=9090
由于此端口仅在 localhost 上开放,因此无法用于任何外部传入连接。
备用获取 URL
如果您有一个自我更新的 Git 仓库代理,该代理比某些代理的原始 Git 仓库要近得多,那么您可以允许这些代理从这个镜像下载源码。 为此,将 teamcity.git.fetchUrlMapping.<name>=<original URL> => <proxy URL> 设置添加到代理配置文件中。 请参阅此部分以获取更多信息: Git VCS 根目录 | 通用设置。
要设置 buildAgent.properties 文件,您可以运行 <Agent_folder>/bin/agent.bat 或 <Agent_folder>/bin/agent.sh 脚本,并使用 configure 命令。 此命令允许您设置核心代理属性并将其保存到目标配置文件中。 如果未指定配置文件路径,更改将保存到默认 <Agent_folder>/conf/buildAgent.properties 属性。
要查看可用参数列表,请使用 --help 标志运行此命令。
./agent.sh configure --help
Java executable is found: '/Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home/bin/java'
Configuring TeamCity build agent...
TeamCity Agent configurator
Usage:
configure PROPERTIES_FILE
configure -f PROPERTIES_FILE
configure [PROPERTIES]
configure --usage
status
status short
Where PROPERTIES format is --key=value or --key value
Supported properties:
* --agent-config-file=PATH - path to build agent properties file (<Agent Root>/conf/buildAgent.properties by default)
* All default properties that can be configured in buildAgent.properties file
Also there are aliases for some of them:
auth-token = authorizationToken
logs-dir = logsDir
name = name
server-url = serverUrl
system-dir = systemDir
temp-dir = tempDir
work-dir = workDir
示例命令,记录服务器 URL 并设置自定义代理名称:
./agent.sh configure --server-url http://localhost:8111/ --name AG2
设置代理服务器后的代理
可以配置前向代理服务器以便代理到服务器的连接。
在 TeamCity 代理端,使用 buildAgent.properties 文件中的以下属性来指定连接到 TeamCity 服务器的代理:
## The domain name or the IP address of the proxy host and the port
teamcity.http.proxyHost=123.45.678.9
teamcity.http.proxyPort=8080
## If the proxy requires authentication, specify the login and password
teamcity.http.proxyLogin=login
teamcity.http.proxyPassword=password
要访问 HTTPS 端点(例如,托管在 GitHub 上的存储库),还需配置 teamcity.https.* 属性。
最后修改日期: 2025年 8月 12日