1

I am modifying a script that clones a Git repository and will be passed in a build definition vNext task "PowerShell". I believe vNext uses PowerShell ISE. Git out puts to standard error (stderr) which causes the vNext step to fail.

The script currently pipes the stdeer to a file to proceed forward. This causes an issue of the vNext not failing when an actual error in the Git clone occurs.

What I want to do is cause a fail in the vNext step when an actual Git error occurs.

I have thought about doing a contains string script on the piped file but I am unsure what the actual cases for a passed instance string and a failed instance string would contain.

Links that I've investigated are:

    https://stackoverflow.com/questions/26872205/powershell-ise-throws-an-error-on-git-checkout
    https://serverfault.com/questions/565875/executing-a-git-command-using-remote-powershell-results-in-a-nativecommmanderror
try{
    $errorDir = [io.path]::combine($repoDir, 'GitErrors.txt')
    Write-Host "GitErrors.txt path: $errorDir"
    if(!(Test-Path ($errorDir))){
        git clone $gitPath 2> GitErrors.txt
        Write-Host "Check if errors exist in GitErrors.txt file"
}
catch{
    $_.Exception.Response.statusCode.Value__
    Write-Host "Message: $_.Exception.Message"
    Write-Host "Could not clone..."
}
Randy Wong
  • 19
  • 2

0 Answers0