2

In my Azure DevOps CD pipeline, I have added a Command Line task which clones a Git repository. The clone is done successfully however there is an error in the log.

The strange behavior is that the clone works perfectly with an Azure hosted agent (like vs2017-win2016 or windows-2019) but generates the error (see below screenshot) if I use a private local agent.

Command Line Script:

git config --global user.email "my@email.com"
git config --global user.name "naregk"
git clone -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" https://naregk.visualstudio.com/txproject/_git/RepoD testrepoD

The stage outcome:

enter image description here

The error which appears:

57.7114907Z ##[command]"C:\Nindows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "C:\agent_work_temp\aae38ede—905d—4d6d-9412-0 57.96819332 ##[error]Cloning into 'testrepoD'... 06.96751142 ##[section]Finishing: Command Line Script

enter image description here

Trevor Reid
  • 3,310
  • 4
  • 27
  • 46
naregkar
  • 363
  • 6
  • 16

1 Answers1

2

Some git command output can be stderr (instead of stdout) and PowerShell think it's an error.

To solve it, you can do something like this:

$result = git clone -c ....... testrepoD 2>&1
Write-Host $result
Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
  • 1
    [This thread](https://stackoverflow.com/questions/34820975/git-clone-redirect-stderr-to-stdout-but-keep-errors-being-written-to-stderr) might give some more ideas how to deal with this situation. – Yan Sklyarenko Sep 04 '19 at 12:29
  • @YanSklyarenko and @Shayki Abramczyk, thanks for the tips. My solution was to use PowerShell and not Command Line task and added `$env:GIT_REDIRECT_STDERR = '2>&1'` before the the `git` commands. – naregkar Sep 05 '19 at 08:26
  • @naregkar you're welcome! only now I saw you specified command line in the question... and I answered with PowerShell script... sorry! your solution is also good :) – Shayki Abramczyk Sep 05 '19 at 08:28