4

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:

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?

4

2 回答 2

3

事实证明,设置有一个相当大的问题。显然出于某种原因,一旦我调用 git,我就不太了解用户上下文/配置文件的更改。这将改变主目录。这可以通过查看执行配置文件更改的 Git 等文件来验证:配置文件:

# 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)"

我通过将主目录强制为当前用户来解决此问题:

set HOME=%env.USERPROFILE%

问题出在 git 的初始化脚本中。

此外,我必须将配置修改为:

Host webshop_github
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa.shop
于 2013-11-22T13:36:19.917 回答
1

实际上,由于@Christian Mikkelsen 和此线程中的答案,我已经深入了解并找到了另一个解决方案:git.cmd vs git.exe - 有什么区别,应该使用哪个?.

git.exe在手动使用 git 时,您不应该使用原始文件,而是使用包装器 -gitk.cmdcmd\git.exe. 请注意,cmd\git.exe它与bin\git.exe. Teamcity 本身使用bin\git.exe它,因为它知道如何使用它。但是如果你手动使用 git,你应该使用cmd\git.exe.

您必须解决的问题是如何将路径传递cmd\git.exe到您的脚本中。我支持它可以使用自定义参数来完成,或者env.TEAMCITY_GIT_PATH在执行脚本之前覆盖它。

于 2014-06-24T04:53:57.960 回答