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


      Enable the option Allow scripts to access OAuth token on the build.


  2. Set the variable system.prefergit to true on the build.


  3. Add a PowerShell-task to the build


  4. 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: