Swallow GIT output in PowerShell run by Team Foundation Server because it’s STDERR which breaks the build

Imagine you want to commit and push a changed file during a build.

  1. Grant the user “Project Collection Build Service (DefaultCollection)” the following permissions on the repository:
    • Contribute
    • Read
  2. Enable the option “Allow scripts to access OAuth token” on the build.
  3. Set the variable “system.prefergit” to “true” on the build.
  4. Add a PowerShell-task to the build
  5. Run…

The issue is that either

a) GIT has no idea what STDERR is and writes success messages to the error stream


b) TFS Build interprets the output of GIT wrong and fails the build even if the exit code is 0. Fun fact: It works with the “Command Line”-Task without any issues.

Both out of my control – maybe another Issue/PR on the GIT project could solve it as it is open source, But I need a solution NOW!

So here is how to modify the script:


Comments are closed