12

I need to execute git commands in a TeamCity build step.

These git commands need to use a SSH-based url for the git repo in order to authenticate as a priviliged user to the git server (because these git commands will actually modify the git repo, not just read it).

I am aware of this question.

I have already VCS checkout mode "Automatically on Agent". The VCS root is correctly configured with ssh and working well.

However, as stated in the documentation, TeamCity

temporarily saves the key on the agent's file system and removes it after git fetch/clone is completed.

So even though the TeamCity correctly used the SSH key during agent-side checkout, the key is intentionally not accessible later in the build.

But I really want to use the key later!

The output that the git commands generate is:

[06:12:29][Step 3/4] Permission denied (publickey).
[06:12:29][Step 3/4] fatal: Could not read from remote repository.
[06:12:29][Step 3/4] 
[06:12:29][Step 3/4] Please make sure you have the correct access rights
[06:12:29][Step 3/4] and the repository exists.

I have confirmed that the known_hosts file exists and contains the appropriate public keys. I have also confirmed that the C:\Users\systeamcityagent\.ssh does not contain any private keys (as expected).

I am running TeamCity Enterprise 9.1.3.

What is the recommended solution for this?

Community
  • 1
  • 1
Klas Mellbourn
  • 35,589
  • 18
  • 119
  • 143
  • Did you get this to work? I am in a similar situation and I am having a hard time getting the ssh agent to work with my git push. – Bronumski Jun 01 '17 at 22:20

1 Answers1

11

Teamcity 9.1 introduced a new Features called SSH Agent that allows you to establish Agent side SSH Connections using Server Stored SSH Keys:

enter image description here

See What´s New in TeamCity 9.1

Mecaveli
  • 1,397
  • 9
  • 16
  • 1
    Can you expand on how the agent or key is used in the command line. I am still having a hard time getting this to work. – Bronumski Jun 01 '17 at 22:19
  • 2
    Check the [official docs](https://confluence.jetbrains.com/display/TCD10/SSH+Keys+Management), it´s very well explained there. You´ll need some basic understanding of SSH Keys but that´s about it. – Mecaveli Jun 08 '17 at 12:06