How to git push from VSTS build

Problem:

When I run a git push from my VSTS build the push works but my build fails.

Solution:

Use the –q switch on your git push command.

Explanation:

By default the PowerShell and Command Line tasks in VSTS will fail if anything is written to standard error which makes perfect sense. 

image

Well it does until a tool writes status messages on standard error.

image

The line starting with “To https://” is the one causing all the issues. It is not an error but being written to standard error which causes the build to fail.

image

Luckily, we can use the –q switch to have it only write real errors to standard error and get the desired results.

image

Now when I run my build the build succeeds.

I also tested that if something bad really happened the build does fail as expected.

Comments (1) -

  • This was really helpful and it got me unstuck from one problem, and onto a new problem! Which is this: I want to push to my remote git repo from a VSTS build, but I can't figure out how to authenticate to it (except by putting the credentials right in the command line, which is terrible). It's the same source I use for the build (a BitBucket repo). The only info I can find on pushing to a git remote in a VSTS build doesn't address how to handle authentication properly. Any guidance? My command line step is currently failing because when I try to push, it wants to prompt for username/password input from the command line.

Add comment

Loading