Team City Git “Host key verification failed”

2019-06-26 01:29发布

问题:

I want to use TeamCity to pull code from a remote Git repo, update a file (and stage and commit to the local repo) and then push the committed file back to the remote repo.

The pull & update is fine. If I open git-bash and git push origin master then the commit (arising from the updated file being committed to the local repo) is pushed to the remote repo. Fine.

If I try to do this (to the same remote target repo) using a Team City's Command Line runner it fails with

    [14:49:18][Step 3/7] Host key verification failed.
    [14:49:18][Step 3/7] fatal: Could not read from remote repository.

The target repo is using Gerrit for authentication. I have uploaded the public key to Gerrit and I have confirmed that the Server Host Key from Gerrit is in C:\Users\AccountName\.ssh\known_hosts. That folder also contains the public and private key.

The fact that I can push using git-bash says to me that the keys are in the correct places, but I am puzzled as to why the Team City Command Line runner is not using them.

For ref the build step's Command Parameters are -c "git push origin master".

Can anyone see what I am missing?

Thanks

回答1:

You have to set TeamCity service to run as the same account that has access to your keys. By default TeamCity uses the "System" account so that's why your keys are not being used.