Push to local Azure DevOps Git from Build Pipeline

To push change to Azure DevOps, you should integrate your credential in Git repo URL:

  • First, create a PAT if you not have.
  • Then use below command to push:

    git push https://Personal%20Access%20Token:[email protected]/YYY/_git/zzz master
    

The answers have become out of date with how Azure Devops works now. To enable authorisation in your pipeline you should use the checkout schema property in your steps so you can persist the credentials for later git commands.

- checkout: self
  persistCredentials: true

You shouldn't have to go the PAT route for auth - according to this, if your repo is part of the same Azure DevOps project as the build pipeline, credentials should just flow. Is it possible you haven't authorized the build agent to write to your repos? Two things are needed:

  • Under Project Settings -> Repositories for your Azure DevOps project, allow the Project Collection Build Service entity Contributor rights to the appropriate repo (or all project repos).

  • Allow scripts to access the OAuth token under the "Agent job" settings:

    enter image description here

Also note a bad gotcha: this won't work for submodule operations, since DevOps does not automatically flow the credentials to the submodule instances, and the only symptom is a silent hang. Workaround to flow credentials manually is found here.