在 TeamCity 构建步骤中使用 git 命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11632624/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using git commands in a TeamCity Build Step
提问by Jake Stevenson
One of my TeamCity v7.0 build projects relies on using a diff between the current development branch and the master branch to determine what needs to be run. I've written a small script that uses something like:
我的 TeamCity v7.0 构建项目之一依赖于使用当前开发分支和主分支之间的差异来确定需要运行的内容。我写了一个小脚本,它使用类似的东西:
git diff origin/master..origin/QA --name-only --diff-filter=AM | DoSomethingWithThoseFiles
Unfortunately, the build log indicates that git diff
is not working. When I go into the buildAgent/work directory for this project, I see that there is no .git
folder, so it cannot perform the git operations required.
不幸的是,构建日志表明这git diff
不起作用。当我进入这个项目的 buildAgent/work 目录时,我看到没有.git
文件夹,因此它无法执行所需的 git 操作。
I've put teamcity.git.use.local.mirrors=true
in the buildAgent.properties
file as mentioned at TW-15873, but that does not seem to help in any way.
我已经按照TW-15873 中提到的方式放入teamcity.git.use.local.mirrors=true
了buildAgent.properties
文件,但这似乎没有任何帮助。
Is there anything I can do to get the list of files changed between two branches in a script for my build step?
我可以做些什么来让我的构建步骤的脚本中的两个分支之间的文件列表发生变化?
回答by Mike Two
回答by AnneTheAgile
@Mike Two's answer is correct, one needs to configure the VCS root to use Checkout mode Automatically on Agent -not- on the server. The TC docs do not mention that this required setting is hidden by default as 'advanced'. So here is a picture of what to look for.
@Mike Two 的回答是正确的,需要配置 VCS 根以在代理上自动使用结帐模式 - 而不是在服务器上。TC 文档没有提到这个必需的设置默认隐藏为“高级”。所以这里是要寻找什么的图片。
FYI, My specific VS2013 Solution step error was from MSBuild, as below. I am using the latest TeamCity Enterprise 9.0 EAP (build 31963).
[PreBuildEvent] Exec
[14:21:55][Exec] git rev-parse --short=9 HEAD > "C:\TeamCity\buildAgent\work\e5e910561e800525\MYPROJECT\bin\Debug\version.txt"
[14:21:55][Exec] fatal: Not a git repository (or any of the parent directories): .git
[14:21:55][Exec] C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1131, 5): error MSB3073: The command "git rev-parse --short=9 HEAD > "C:\TeamCity\buildAgent\work\e5e910561e800525\Higgens\bin\Debug\version.txt"" exited with code 128.
[14:21:55]
仅供参考,我的特定 VS2013 解决方案步骤错误来自 MSBuild,如下所示。我使用的是最新的 TeamCity Enterprise 9.0 EAP(内部版本 31963)。
[PreBuildEvent] Exec
[14:21:55][Exec] git rev-parse --short=9 HEAD > "C:\TeamCity\buildAgent\work\e5e910561e800525\MYPROJECT\bin\Debug\version.txt"
[14:21:55][Exec] fatal: Not a git repository (or any of the parent directories): .git
[14:21:55][Exec] C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1131, 5): error MSB3073: The command "git rev-parse --short=9 HEAD > "C:\TeamCity\buildAgent\work\e5e910561e800525\Higgens\bin\Debug\version.txt"" exited with code 128.
[14:21:55]
//edit; I didn't know how to add this to a comment.
//编辑; 我不知道如何将此添加到评论中。