Search code examples
gitpushteamcityagent

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 protected]
    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 (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?


Solution

  • 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