35

Has anybody successfully configured Teamcity to monitor, extract, and build from GitHub?

I can't seem to figure how where and how to configure the SSH keys for Teamcity. I have Teamcity running as a system service, under a system account. So where does Teamcity stash its SSH configuration?

EDIT

To get this to work, I needed to stop the agent from running under a system account.

Ryan Hayes
  • 5,290
  • 4
  • 42
  • 52
Jeff Fritz
  • 9,821
  • 7
  • 42
  • 52

8 Answers8

28

Ok... I got this to start working on my Windows server. Here are the steps I took to configure TeamCity 4.5 Professional:

  1. Downloaded the JetBrains Git VCS Plugin
  2. Copied the downloaded zip file to .BuildServer\plugins
  3. In the Administration > Edit Build Configuration > Edit VCS Root configuration screen, I selected "Git (JetBrains)"
  4. Entered my Clone Url from the GitHub project page
  5. Set for authentication method "Default Private Key" -- this is IMPORTANT
    1. The TeamCity BuildAgent should be running as a standard user, with the SSH installation configured properly for that user.
    2. Follow the GitHub SSH directions for SSH configuration
  6. Leave the username blank. This should already be provided for in your GitHub clone URL
Jeff Fritz
  • 9,821
  • 7
  • 42
  • 52
  • I've got this working with TeamCity 5.1.2 using Private Key Authentication. The user that the Build Agent is running as has a private key in its home directory. Authentication didn't work until I left the username blank. I thought I would have to specify it because my clone URL belonged to another user, but I assume it is using the user that the Build Agent is running as. – Martin Owen Jul 14 '10 at 11:54
  • 9
    Be aware that this doesn't work if you're using SSH keys generated in PuttyGen - we spent quite a while messing around, before regenerating a key using ssh-keygen in GitBash which then worked immediately. – dwynne Aug 24 '10 at 14:16
  • Also doesn't help if you haven't stored the keys in the standard SSH directory on C:\.ssh\config\. There doesn't appear to be a setting available to tell TeamCity it is elsewhere. – Rebecca Feb 07 '11 at 20:39
  • Was anyone able to get this working when TeamCity agent is running as local-system (whose profile is c:\windows\system32\config\systemprofile) _and_ with a key (generated from ssh-keygen) with a non-standard name? According to their docs (http://confluence.jetbrains.net/display/TCD5/Git+%28JetBrains%29) TeamCity wants to look in \.ssh\config for the ssh config file http://linux.die.net/man/5/ssh_config but then I didn't get IdentityFile in there to work (not sure if it wants windows or posix paths...). – Peter Mounce Nov 04 '11 at 23:09
8

I got "Default Private Key" to work with agents running as the SYSTEM user on Windows. For me, the answer was having the identity file at

C:\Windows\SysWOW64\config\systemprofile\.ssh\id_rsa

instead of at

C:\Windows\System32\config\systemprofile\.ssh\id_rsa

Dan
  • 3,665
  • 1
  • 31
  • 39
4

Your question is specific to SSH, but it is certainly easier and quicker to use HTTP over TLS, as GitHub and TeamCity both now support HTTP authentication. Furthermore, GitHub also supports personal api tokens with limited permissions, that you may configure to your liking, or create a new user if you prefer.

See image below of our TeamCity settings.

Teamcity configuration

David Mohundro
  • 11,922
  • 5
  • 40
  • 44
2

Since TeamCity 8.1, there is an official support for SSH key management, please read this docs: https://confluence.jetbrains.com/display/TCD9/SSH+Keys+Management

KIR
  • 5,614
  • 1
  • 31
  • 23
1

(This is a up to date answer to an old question)

I got ssh based builds working with github/gitlab and teamcity 7 like this:

Log onto the teamcity machine and use puttygen/ssh-keygen to generate a rsa key pair and save the openssh key somewhere sensible. (Gotcha - Using puttygen? Make sure the private key is in openssh format - puttygen > conversions > export openssh key)

I suggest you save the private key in

C:\.ssh\id_rsa

Now setup "default private key" in teamcity - create a file

C:\.ssh\config

And in it place this:

Host * IdentityFile c:\.ssh\id_rsa

Login to your gitlab/guthub account and paste in the openssh public key for your teamcity private key.

You should now be able to create a git vcs root in teamcity that can use the default private key to pull your source.

alastairtree
  • 3,960
  • 32
  • 49
1

for private key, username must be blank.

Davem M
  • 477
  • 7
  • 9
0

I don't know why but choosing Default Private Key failed to me.

Then I choose to Custom Private Key as screen shot below: enter image description here

The Username field has to be empty.

The Passphrase field is the password of the your private key

(Assume you have added the public key of this private key in git already.)

Hope no one got stuck like me !

ThangTD
  • 1,586
  • 17
  • 16
0

You may need a third party plugin like this

Dean
  • 5,896
  • 12
  • 58
  • 95
  • 12
    For future readers, that plugin was deprecated when JetBrains created an official one for git support that ships in TeamCity. – Peter Mounce Nov 04 '11 at 23:06