How to set up SSH authenticated git commands in a TeamCity build step
Teamcity 9.1 introduced a new Features called SSH Agent that allows you to establish Agent side SSH Connections using Server Stored SSH Keys:
See What´s New in TeamCity 9.1
Klas Mellbourn
web developer, consultant, Git enthusiast e-mail: [email protected] GitHub: https://github.com/Mellbourn
Updated on June 13, 2022Comments
-
Klas Mellbourn almost 2 years
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 theC:\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?
-
Bronumski almost 7 yearsCan 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.
-
Mecaveli almost 7 yearsCheck the official docs, it´s very well explained there. You´ll need some basic understanding of SSH Keys but that´s about it.
-
uthomas about 2 yearsoh, this really saved my @55 from trying to re-invent the wheel.