TeamCity – Git push from agent
I’ve got a TeamCity server set up to checkout src from GitHub on the agents using “Default Private Key” and a config file in .ssh that looks like this:
Host email@example.com IdentityFile ~/.ssh/id_rsa.shop StrictHostKeyChecking no Host github.com IdentityFile ~/.ssh/id_rsa.shop StrictHostKeyChecking no
and this works fine.
Now i want to push from the agents.
However when i do this the push command hangs due to user input:
The authenticity of host 'github.com (188.8.131.52' can't be established. RSA key fingerprints is 'xxx....xxx' Are you sure you want to continue (yes/no) Warning: Permently added '' to known hosts. Connection closed by 184.108.40.206 Fatal: The remote end hung up unexpectedly.
If i do this manually it still fails with permission denied no matter wether i type yes/no.
The “Default Private Key” has read/write permissions accoring to github, so im a bit lost.
Only thing i have observed is that the github ip looks very local, but how can that be when the agent has just done a agent side checkout? Could this be a firewall?
Can anyone explain to me what im missing?
2 Solutions collect form web for “TeamCity – Git push from agent”
Turns out there was a rather big catch with the setup.
Apperently for reason i do not quite understand the user context/profile changed once i called git.
This would change the homedir.
This can be verified by looking at the Git etc file which does the profile change called: profile:
# Set up USER's home directory if [ -z "$HOME" -o ! -d "$HOME" ]; then HOME="$HOMEDRIVE$HOMEPATH" if [ -z "$HOME" -o ! -d "$HOME" ]; then HOME="$USERPROFILE" fi fi if [ ! -d "$HOME" ]; then printf "\n\033[31mERROR: HOME directory '$HOME' doesn't exist!\033[m\n\n" echo "This is an error which might be related to msysGit issue 108." echo "You might want to set the environment variable HOME explicitly." printf "\nFalling back to \033[31m/ ($(cd / && pwd -W))\033[m.\n\n" HOME=/ fi # normalize HOME to unix path HOME="$(cd "$HOME" ; pwd)"
I fixed this issue by forcing the home dir to current user as so:
The problem was in an init script of git.
Moreover I had to modifiy the config to:
Host webshop_github HostName github.com User git PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa.shop
Actually I’ve dipped a bit further and found another solution thanks to @Christian Mikkelsen and answers in this thread: git.cmd vs git.exe – what is the difference and which one should be used?.
You just should not use the original
git.exe when manually working with git, but the wrappers –
cmd\git.exe. Please note that
cmd\git.exe isn’t the same as
bin\git.exe. Teamcity itself uses
bin\git.exe as it knows how to work with it. But if you work with git manually you should use
The problem you have to solve is how to pass the path to
cmd\git.exe into your script. I support it can be done using custom parameters or perhaps overriding the
env.TEAMCITY_GIT_PATH before executing your script.