You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

新增TeamCity Agent无法创建临时目录,如何配置权限?

TeamCity构建Agent临时目录权限修复方案

问题背景

添加新TeamCity构建Agent后,分配任务时触发错误:

Agent failed to create build temp directory at /home/switchbuild/BuildAgent/temp/buildTmp.
Please check agent has necessary permissions and there is enough free space on disk.

已通过磁盘检查排除空间不足问题:

build5:~/BuildAgent/temp$ df -h
Filesystem             Size  Used Avail Use% Mounted on
udev                   3.9G     0  3.9G   0% /dev
tmpfs                  798M   18M  781M   3% /run
/dev/sda1             1000G   40G  910G   5% /

权限修复步骤

1. 确认TeamCity Agent的运行用户

执行以下命令查看Agent进程的运行用户:

ps aux | grep teamcity-agent
# 或通过systemd服务查看
systemctl status teamcity-agent

输出中会显示Agent进程所属的用户(例如teamcity或switchbuild)。

2. 检查目标目录权限

查看临时目录的所有者和权限设置:

ls -ld /home/switchbuild/BuildAgent/temp

正常输出示例:drwxr-xr-x 2 switchbuild switchbuild 4096 Aug 1 10:00 /home/switchbuild/BuildAgent/temp

3. 修复目录权限

根据Agent运行用户与目录所有者的关系,选择以下方法:

  • 方法一:修改目录所有者为Agent运行用户
    将整个BuildAgent目录的所有者替换为Agent运行用户,确保递归生效:

    sudo chown -R [agent-user]:[agent-group] /home/switchbuild/BuildAgent
    

    示例(若Agent用户为teamcity):

    sudo chown -R teamcity:teamcity /home/switchbuild/BuildAgent
    
  • 方法二:添加组写权限
    若Agent用户属于目录所在的用户组,可开放组写入权限:

    sudo chmod -R g+w /home/switchbuild/BuildAgent/temp
    
  • 方法三:调整Agent服务运行用户
    若使用systemd管理Agent服务,编辑服务配置文件:

    sudo nano /etc/systemd/system/teamcity-agent.service
    

    修改User=和Group=字段为拥有目录权限的用户(例如switchbuild),保存后重启服务:

    sudo systemctl daemon-reload
    sudo systemctl restart teamcity-agent
    

4. 验证权限修复

切换到Agent运行用户,手动测试目录创建:

su - [agent-user] -c "mkdir /home/switchbuild/BuildAgent/temp/testDir && rmdir /home/switchbuild/BuildAgent/temp/testDir"

若未报错,说明权限已修复,重新分配构建任务即可。


内容的提问来源于stack exchange,提问作者RAZ_Muh_Taz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 02:28:38