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 git@github.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:

  • TeamCity agent error “failed to perform checkout on agent”
  • The authenticity of host 'github.com (192.30.252.130' 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 192.30.252.130
    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?

  • How to find Github forks of a deleted project?
  • What should one do with media assets related to a Git repository?
  • How Git select the rebase starting point?
  • What does Fast-forward mean when pulling from remote?
  • Use git rev-list to exclude a branch, but keep common ancestors with the included branches
  • Propogate file renames in Visual Studio (2013) to GIT as GIT renames?
  • 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:

    set HOME=%env.USERPROFILE%
    

    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 – gitk.cmd or 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 cmd\git.exe.

    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.

    Git Baby is a git and github fan, let's start git clone.