Reputation: 241
I am trying to clone a repository from VSTS. I am trying to do it using powershell, and using a server that has no access to the internet, except to MyVSAccount.VisualStudio.com, so that I can clone repositories.
I am able to "talk" to my VS account using my username and a Token. I get back a list of all my repositories with info about them.
Following that, however, I get an error when trying to clone it. It just says: connection refused to MyVSAccount.VisualStudio.com.
Using fiddler, I can see that only when I retrieve the list of repositories that there is a http request to my VS account. When cloning, there isn't any, so there shouldn't be refusal. Plus, there is access to that address of my account, so there shouldn't be problems in cloning.
Has anyone got a suggestion for this? I don't get it why when there is an http request to retrieve the list of repositories, all is successful, and when cloning it isn't, even though there is no http request for cloning.
Is there a proxy set up that is necessary to insert in the code?
Code to clone
git clone --mirror $url
Code to retrieve the list of repositories using a Token.
$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
Error:
fatal: unable to access 'MyVSAccount.visualstudio.com/MyProject/_git/Tests/';: Could not resolve host: myvsaccount.visualstudio.com
I also tried to set up proxy with:
$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)
Upvotes: 2
Views: 1132
Reputation: 38116
Since the variable $url
you defined should with the value https://MyVSAccount.VisualStudio.com
. while the URL of git repo in VSTS should with the format https://MyVSAccount.visualstudio.com/projectname/_git/reponame
.
So you should use VSTS repo url not VSTS account url to clone a mirror repo. Script to clone a git repo as:
$repourl=$url+"/projectname/_git/reponame"
git clone --mirror $repourl 2>&1|write-Host
Besides, please make sure config git to use the proxy. The command to config proxy for git as below:
git config --global http.proxy http://proxyUsername:[email protected]:port
More details, you can refer Configure Git to use a proxy and Getting git to work with a proxy server.
Upvotes: 2