【问题标题】:Cloning Repositories - Connection Refused克隆存储库 - 连接被拒绝
【发布时间】:2018-02-08 20:20:00
【问题描述】:

我正在尝试从 VSTS 克隆存储库。 我正在尝试使用 powershell 并使用除了 MyVSAccount.VisualStudio.com 之外无法访问 Internet 的服务器,以便我可以克隆存储库。

我可以使用我的用户名和令牌与我的 VS 帐户“交谈”。我会返回我所有存储库的列表以及有关它们的信息。

但是,之后,我在尝试克隆它时遇到错误。它只是说:连接到 MyVSAccount.VisualStudio.com 被拒绝。

使用提琴手,我可以看到,只有当我检索存储库列表时,我的 VS 帐户才会有 http 请求。克隆时,没有,所以不应该拒绝。另外,可以访问我帐户的那个地址,所以克隆应该没有问题。

有人对此提出建议吗?我不明白为什么当有检索存储库列表的 http 请求时,一切都成功,而在克隆时却没有,即使没有用于克隆的 http 请求。

是否需要在代码中插入代理设置?

要克隆的代码

git clone --mirror $url

使用令牌检索存储库列表的代码。

$url = $h.Get_Item("Url")
$username = $h.Get_Item("Username")
$password = $h.Get_Item("Password")

# Retrieve list of all repositories
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
$headers = @{
    "Authorization" = ("Basic {0}" -f $base64AuthInfo)
    "Accept" = "application/json"
}

Add-Type -AssemblyName System.Web
$gitcred = ("{0}:{1}" -f  [System.Web.HttpUtility]::UrlEncode($username),$password)



$resp = Invoke-WebRequest -Headers $headers -Uri ("{0}/_apis/git/repositories?api-version=1.0" -f $url)
$json = convertFrom-JSON $resp.Content

错误:

致命:无法访问 'MyVSAccount.visualstudio.com/MyProject/_git/Tests/';:不能 解析主机:myvsaccount.visualstudio.com

我也尝试设置代理:

$proxyString = "http://proxy-s-app.mynet.net:80"
$proxyUri = new-object System.Uri($proxyString)
[System.Net.WebRequest]: : DefaultWebProxy = new-object System.Net.WebProxy ($proxyUri, $true)

【问题讨论】:

    标签: git powershell proxy azure-devops


    【解决方案1】:

    由于您定义的变量$url 应该具有值https://MyVSAccount.VisualStudio.com。而 VSTS 中 git repo 的 URL 应该是 https://MyVSAccount.visualstudio.com/projectname/_git/reponame 格式。

    所以你应该使用 VSTS repo url 而不是 VSTS account url 来克隆镜像 repo。将 git repo 克隆为的脚本:

    $repourl=$url+"/projectname/_git/reponame"
    git clone --mirror $repourl 2>&1|write-Host
    

    此外,请确保配置 git 以使用代理。为 git 配置代理的命令如下:

    git config --global http.proxy http://proxyUsername:proxyPassword@proxy.server.com:port
    

    更多详情,可以参考Configure Git to use a proxyGetting git to work with a proxy server

    【讨论】:

    • 我曾尝试使用您之前写的克隆网址,但出现同样的错误。致命:无法访问“MyVSAccount.visuallstudio.com/MyProject/_git/Tests”:无法解析主机:myvsaccount.visualstudio.com
    • 如果直接通过命令行克隆 git repo 会怎样(命令 `git clone MyVSAccount.visuallstudio.com/MyProject/_git/Tests')?
    • 同样的错误无法完成。而且我还想在 Powershell ISE 脚本中使用它,以便以后可以实现自动化。我在无法访问 Internet 的服务器上运行此程序,MyVSAccount.VisualStudio.com 除外。我认为这可能是问题所在。
    • 你在git中配置代理了吗?如果你还没有在 git 中配置代理,你可以配置它(我在答案末尾添加了),然后再试一次。
    • 它是代理!谢谢您的帮助。 :)
    猜你喜欢
    • 2012-08-07
    • 1970-01-01
    • 2016-05-18
    • 2018-09-21
    • 2014-01-08
    • 2013-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多