如何从在 LocalSystem 帐户下运行的 rake 正确设置 git commit --author?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5203436/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:09:12  来源:igfitidea点击:

How to set git commit --author properly from rake running under LocalSystem account?

gitrakecommitauthor

提问by ?ukasz Podolak

I have Rake build script for my CI process running under TeamCity@windows. One of the steps that the script does is to commit some changes to remote repository (this repository represents real production environment on my shared hosting. It has only ftp access, so I map this location as a windows drive)

我有在 TeamCity@windows 下运行的 CI 进程的 Rake 构建脚本。该脚本执行的步骤之一是向远程存储库提交一些更改(此存储库代表我共享主机上的真实生产环境。它只有 ftp 访问权限,因此我将此位置映射为 Windows 驱动器)

Part of ruby looks like this:

部分 ruby​​ 如下所示:

  sh "git commit -v -m #{version_tag}"

However, when script is run by teamcity build agent (which runs under LocalSystem account), I get the following warning:

但是,当脚本由 teamcity 构建代理(在 LocalSystem 帐户下运行)运行时,我收到以下警告:

[master e7a5a8d] v0.4.7.0
Committer: unknown <SYSTEM@.(none)>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email [email protected]
If the identity used for this commit is wrong, you can fix it with:
git commit --amend --author='Your Name <[email protected]>'
9 files changed, 0 insertions(+), 0 deletions(-)

Reading what's written I altered my rake script command to:

阅读所写的内容,我将 rake 脚本命令更改为:

  sh "git commit --author='TeamCity <[email protected]>' -v -m #{version_tag}"

but this command results with a weird failure (previously commit was successful, but with warning). This is the only thing I get as an output from TeamCity build log:

但是这个命令会导致一个奇怪的失败(以前提交成功,但有警告)。这是我从 TeamCity 构建日志中得到的唯一输出:

git commit --author='TeamCity <[email protected]>' -v -m v1.0.18.10
[19:06:20]: [Execute _3_deployment_stage:to_ftp] The system cannot find the file specified.

How can I successfully set up an author for a commit for script running under LocalSystem account ?

如何为在 LocalSystem 帐户下运行的脚本的提交成功设置作者?

回答by ?ukasz Podolak

I found a different solution to my problem. I configured TeamCity agent to run under custom windows account. I needed to log in to this account, and set both:

我找到了一个不同的解决方案来解决我的问题。我将 TeamCity 代理配置为在自定义 Windows 帐户下运行。我需要登录到这个帐户,并设置:

git config --global user.email [email protected]
git config --global user.name TeamCity

With this set up, the command:

有了这个设置,命令:

sh "git commit --author='TeamCity <[email protected]>' -v -m #{version_tag}"

still generates the weird: "The system cannot find the file specified." error. However, having account settings set up globally I could remove the --author option from the commit statement, leaving it with:

仍然生成奇怪的:“系统找不到指定的文件。” 错误。但是,在全局设置帐户设置后,我可以从提交语句中删除 --author 选项,将其保留为:

sh "git commit -v -m #{version_tag}"

and that produces the desired effect.

这会产生预期的效果。