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

如何从TeamCity服务器修改构建代理工作目录至其他路径?

Troubleshooting "File Not Found" When Running Autodeploy.bat from TeamCity

Looks like your Autodeploy.bat script is hitting a snag when trying to locate zip files in the target directory. Let's break down the issue and fix it step by step.

First, let's recap the execution log you shared:

Starting:C:\AUTOEBCDeployment\Autodeploy.bat in directory: D:\ProgramData\JetBrains\TeamCity BuildAgent\work\8a77def6c3e16d10
D:\ProgramData\JetBrains\TeamCity BuildAgent\work\8a77def6c3e16d10>cd C:\AUTOEBCDeployment\dist
D:\ProgramData\JetBrains\TeamCity BuildAgent\work\8a77def6c3e16d10>for /F "tokens=*" %a in ('dir /b /a-d *.zip') do set DIST_FILE=%a
File Not Found

This error typically means one of two things: either the target directory has no .zip files, or the script didn't actually switch to the intended directory before running the dir command. Here's how to diagnose and fix each scenario:

1. Verify the target directory has zip files and exists

Log into the TeamCity build agent server manually and check C:\AUTOEBCDeployment\dist:

  • Confirm the directory itself exists (if not, create it as part of your deployment pipeline or manually)
  • Check if there are any .zip files present. If not, trace back your build process to make sure the artifacts are being generated and copied to this location correctly.

2. Ensure the cd command actually succeeds

The log shows the cd command was executed, but it doesn't tell us if it worked. Add error checking to your batch script to catch directory switching failures:

cd C:\AUTOEBCDeployment\dist
if %errorlevel% neq 0 (
    echo ERROR: Failed to switch to directory C:\AUTOEBCDeployment\dist
    exit /b 1
)

This will immediately exit the script with a clear error message if the directory doesn't exist or the agent lacks permissions to access it.

3. Use an absolute path in the dir command

Avoid relying on the current working directory entirely. Modify your for loop to target the zip files directly with a full path:

for /F "tokens=*" %%a in ('dir /b /a-d "C:\AUTOEBCDeployment\dist\*.zip"') do set DIST_FILE=%%a

(Note: In batch files, you need to use double percent signs %%a instead of single %a for loop variables.)

4. Check TeamCity agent permissions

Make sure the Windows service account running the TeamCity build agent has read access to C:\AUTOEBCDeployment\dist. Sometimes restricted service accounts can't access certain directories, even if they exist. You can test this by running the batch script manually under the same service account to replicate the issue.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 08:00:35