4
votes

I'm trying to get TeamCity to build my private GitHub repository. I'm able to successfully get my VCS root to pass the connection test when I explicitly set the path to the key file; however, despite lots of Googling, I can't get it to work when I use the 'Default Private Key' option. I get com.jcraft.jsch.JSchException: Auth fail.

Both my TeamCity server and build agent are running as a user called (gasp) teamcity, and the contents of C:\users\teamcity\.ssh\ include both a config and a key file, where the config is pointing to the key file. My config contains:

Host *
    IdentityFile ~/.ssh/github.key

I've tried a variety of different path styles, both Windows and Unix style, but none seem to work.

Again, it works fine if I use the private key setting and explicitly set the path to the key file, but not when I use the default private key, which I apparently need for my build agent to work.

3
I was able to work around this by using username/password authentication, but I'd much rather use a key. - FMM
Did you figure this out? - stackular
Nope =( still using username / password. - FMM
@FMM I am thinking it has to do with the passphrase. Have you tried creating an SSH key pair without a passphrase? - rf43
@FMM you have exactly my problem. Could you ever solve it using the default private key? - Elisabeth

3 Answers

4
votes

Easiest solution for me was this:

  1. Upload your (OpenSSH) key under your Pipeline's project settings "SSH Keys" (as seen below):

    Pipeline - Project settings (ssh)

    Look at resource links for OpenSSH info (why/how)

  2. And then in VCS root settings, Update "Authentication Settings" as seen below:

    enter image description here

    • note: the username is; "git" (see 3rd resource)
  3. Make sure your "Fetch URL" look something like "[email protected]:ProjectName/RepositoryName.git" - (Note: Github equivalent is required here)

  4. Add your new key (see 1st resource)

Resources:

2
votes

Git looks for the .ssh folder by forming a path with %HOMEDRIVE%/%HOMEPATH%. I've found that even though the %USERPROFILE% environment variable is set correctly these are not set. If %HOMEDRIVE% is empty %SYSTEMDRIVE% will be used instead so by default it will look for .ssh folder in c:\ (or whatever your system drive is).

You can check the environment variables an agent has via the agent parameters tab when selecting an agent and what a build is using via the parameters tab of the build.

Solution 1

create .ssh folder in c:

Solution 2

Set environment variables for %HOMEDRIVE% & %HOMEPATH% to match where your userprofile is

Solution 3

git also can use %HOME% environment variable this is the full path i.e. equal %USERPROFILE%

0
votes

default private key also disabled when one use http://... url and not git@...