为什么构建后步骤 (xcopy) 有时会在 TeamCity 构建中以代码 2 退出? [英] Why would a post-build step (xcopy) occasionally exit with code 2 in a TeamCity build?

查看:52
本文介绍了为什么构建后步骤 (xcopy) 有时会在 TeamCity 构建中以代码 2 退出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我客户解决方案中的一些项目具有构建后事件:xcopy 将构建输出发送到特定文件夹.这在本地构建时工作正常.但是,在 TeamCity 中,我偶尔得到

A few projects in my client's solution have a post-build event: xcopy the build output to a specific folder. This works fine when building locally. However, in TeamCity, I occasionally get

xcopy [...] 以代码 2 退出

xcopy [...] exited with code 2

如果我使用常规的 copy,它会以代码 1 退出.我希望这与文件锁定有关,尽管被复制的特定文件不一样,所以也许只是锁定共享目标目录.我使用 /y 不提示覆盖文件.

If I use regular copy, it exits with code 1. I expect this has something to do with file locks, although the specific files being copied are not the same, so perhaps just locking on the shared destination directory. I use /y to not prompt on overwriting files.

为什么这会在 TeamCity 中失败,而在本地却没有?

Why this fails in TeamCity but not locally?

推荐答案

即使你为 xcopy 提供了 /Y 开关,当 xcopy 不知道您正在复制的是文件或目录.此错误将显示为以代码 2 退出".当您在命令提示符下运行相同的 xcopy 时,您会看到 xcopy 要求响应文件或目录.

Even if you provide the /Y switch with xcopy, you'll still get an error when xcopy doesn't know if the thing you are copying is a file or a directory. This error will appear as "exited with code 2". When you run the same xcopy at a command prompt, you'll see that xcopy is asking for a response of file or directory.

要通过自动构建解决此问题,您可以使用管道回显预定义的响应.

To resolve this issue with an automated build, you can echo in a pre-defined response with a pipe.

要说你复制的是一个文件,在F中回显:

To say the thing you are copying is a file, echo in F:

echo F|xcopy /y ...

要说你复制的是一个目录,在D中回显:

To say the thing you are copying is a directory, echo in D:

echo D|xcopy /y ...

有时可以通过简单地使用复制命令而不是 xcopy 来解决上述问题:

Sometimes the above can be resolved by simply using a copy command instead of xcopy:

copy /y ...

但是,如果有不存在的目录通向最终文件目的地,则会发生以代码 1 退出".

However, if there are non-existent directories leading up to the final file destination, then an "exited with code 1" will occur.

记住:谨慎使用 /C 开关和 xcopy.

Remember: use the /C switch and xcopy with caution.

这篇关于为什么构建后步骤 (xcopy) 有时会在 TeamCity 构建中以代码 2 退出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆