TFS Build hangs when clicking on remote reputation
I wrote a powershell script that I execute before testrunner in (tfs build 2013). The line hangs when the script calls git pushing to the remote repository using ssh. If I run the same script from powershell in a build agent using the same user, it works completely fine. If it's run through the build controller, it just hangs.
I have a test system on my local network where it also works fine. The staging server is hosted outside of this environment. But as I said, it works when I execute the script as the same user directly from the powerselll build agent.
this is what i do
Set-Location $Env:TF_BUILD_SOURCESDIRECTORY
$gitArgs = @(
'remote -v add {0} ssh://{1}@{2}{3}' -f $DeploymentEnvironment, $DeploymentUser, $ServerHost, $ServerRepoPath; ,
'push -v --progress {0} master ' -f $DeploymentEnvironment; )
Write-Verbose "Executing git commands"
$gitArgs | ForEach {
Write-Host $_
$proc = Start-Process -FilePath $GitExe -ArgumentList $_ -Wait -NoNewWindow;
if($proc.ExitCode -ne 0){
Write-Error "Git is having errors..."
exit $proc.ExitCode
}
}
This is the build log output I receive:
remote -v add stage ssh: // user @ MYSERVERIP /path/to/my/repo.git
push -v - master creation wizard
Pushing to ssh: // user @ MYSERVERIP /path/to/my/repo.git
source to share
After hours of research, I finally found a solution.
There are actually two .ssh directories on the build agent. If you are using powershell directly using one from the user directory. During build it uses the .ssh directory from C: \ Program Files \ Git.ssh \
add hosts to your known_host file and copy them to both directories (!).
source to share
I had a similar problem when I was switching from http to ssh.
To execute this command, I ran the following command:
remote set-url origin $sshRemoteUrl
I even checked that everything was correct:
git remote get-url origin
Only after testing in powershell on the build server, looking up SSH records and what not, I found that the set-url command only changes the fetch link, not the push link. This requires --push
:
remote set-url origin $sshRemoteUrl --push
source to share