【问题标题】:TeamCity - Git push from agentTeamCity - 来自代理的 Git 推送
【发布时间】:2013-09-25 21:10:44
【问题描述】:

我已经设置了一个 TeamCity 服务器,以使用“默认私钥”和 .ssh 中的配置文件从代理上的 GitHub 签出 src,如下所示:

Host git@github.com
    IdentityFile ~/.ssh/id_rsa.shop
    StrictHostKeyChecking no

Host github.com
    IdentityFile ~/.ssh/id_rsa.shop
    StrictHostKeyChecking no

这很好用。 现在我想从代理那里推。 但是,当我这样做时,由于用户输入,推送命令会挂起:

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.

如果我手动执行此操作,无论我输入是/否,它仍然会失败并拒绝权限。

“默认私钥”具有根据 github 的读/写权限,所以我有点失落。 我观察到的唯一一件事是 github ip 看起来非常本地,但是当代理刚刚完成代理端结帐时怎么会这样呢?这可能是防火墙吗?

谁能向我解释我缺少什么?

【问题讨论】:

    标签: git push teamcity agent


    【解决方案1】:

    实际上,感谢@Christian Mikkelsen 和此线程中的答案,我已经进一步了解并找到了另一个解决方案:git.cmd vs git.exe - what is the difference and which one should be used?

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

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

    【讨论】:

      【解决方案2】:

      事实证明,设置有一个相当大的问题。 显然出于某种原因,一旦我调用 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
      

      【讨论】:

      • 这真的很奇怪。我在 Windows 代理上遇到了同样的问题。我已经使用您的解决方案解决了它。非常感谢!
      猜你喜欢
      • 1970-01-01
      • 2014-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-30
      • 2019-04-09
      相关资源
      最近更新 更多