Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up SSH authenticated git commands in a TeamCity build step

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?

like image 792
Klas Mellbourn Avatar asked Nov 25 '15 13:11

Klas Mellbourn


1 Answers

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

like image 161
Mecaveli Avatar answered Oct 18 '22 13:10

Mecaveli