How to set git commit --author properly from rake

2019-04-06 10:53发布

问题:

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)

Part of ruby looks like this:

  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:

[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 you@example.com
If the identity used for this commit is wrong, you can fix it with:
git commit --amend --author='Your Name <you@example.com>'
9 files changed, 0 insertions(+), 0 deletions(-)

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

  sh "git commit --author='TeamCity <no@email.com>' -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:

git commit --author='TeamCity <no@email.com>' -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 ?

回答1:

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:

git config --global user.email some@email.com
git config --global user.name TeamCity

With this set up, the command:

sh "git commit --author='TeamCity <some@email.com>' -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:

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

and that produces the desired effect.