2

I am running TeamCity (9.x) on Windows under the local system account. I have installed mysysgit on the server also. I want to run a script via TC using a command line build step that pushes to a git repo. The repo is secure so team city must authenticate. How do I achieve this? The credential-store is per user so not sure how I could store the creds under the local system context. Access to git is over http.

Myles McDonnell
  • 11,575
  • 14
  • 56
  • 96

1 Answers1

2

Make sure to not install the obsolete msysgit, but the new Git for Windows.

I want to run a script via TC using a command line build step that pushes to a git repo. The repo is secure so team city must authenticate.

All you need is to use an http url which includes the username.

https://<username>@yourserver/<username>/<barerepo.git>

You can then set a git config credential.helper netrc which will look for %HOME%_netrc file for the username and password.
I use an encrypted one, but since TC wouldn't be able to enter the gpg private key passphrase anyway, you are better off experimenting with an _netrc file in plain text.

machine yourserver
login username
password a_password
protocol https

Make sure the global setting is set for the same user account as the one used by TeamCity to run.

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • @MylesMcDonnell it is a literal command, which will make git call the [`git-credential-netrc`](https://github.com/git/git/blob/master/contrib/credential/netrc/git-credential-netrc) in order to get the password for a given user and http url. – VonC Nov 14 '15 at 15:02
  • yep, got it..windows caught me out by adding .txt to the _netrc file. works now, thanks – Myles McDonnell Nov 14 '15 at 15:02
  • where is git.exe now that I have installed the latest git for windows? – Myles McDonnell Nov 14 '15 at 15:20
  • @MylesMcDonnell http://stackoverflow.com/a/7671364/6309 or http://stackoverflow.com/a/11928949/6309: with the setup, it probably is in `C:\Program files\Git\bin\git.exe`. – VonC Nov 14 '15 at 15:22
  • On my server, "system" didn't have the "HOME" environmental variable set. I fixed this by adding the following line to the beginning of my powershell script: `set-variable -Force HOME C:\home`. This allowed git to find the credentials in c:\home\_netrc – Josh Aug 01 '17 at 22:57