Why Can't I Push to Azure Git From DevOps Pipeline

1.7k Views Asked by At

The error message is (TF401027: You need the Git 'GenericContribute' permission to perform this action. Details: identity 'Build\8ec5f0f1-6bca-4182-bb3e-2d47a64262bf', scope 'repository'.)

I've taken that GUID and confirmed that the account it represents has all of the necessary permissions on the repo, plus more:

  • Contribute
  • Create branch
  • Read
  • Bypass policies when pushing

The target branch is not locked and there are no policies applied.

The relevant portion of the YAML for my pipeline looks like this:

steps:
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      git config --global user.email "[email protected]"
      git config --global user.name "Build Agent1"
    pwsh: true

- checkout: self
  persistCredentials: true
  
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    pwsh: true
    script: |
      Write-Host "------------------------------------------------------------"
      # Update the file src\version.ts here
      git add src\version.ts
      git commit -m "Version bump from build pipeline [skip ci]"
      git push origin HEAD:Eval 

Eval is the name of the branch I'm pushing to (the same branch the pipeline is running against). The version file gets updated but the last line fails. I've tried it without the HEAD:Eval but then I get an error that I'm in a disconnected Head state and need to add HEAD:branchName

Update: Here's an image showing permissions for the account referenced by the GUID from the error message: Permisisons for Build Account

2

There are 2 best solutions below

0
TimTheEnchanter On BEST ANSWER

I was able to make this work by setting the security for the build account ({Project Name} Build Service ({organization}) ) on the specific branch instead of just on the repo itself. In the Branches page, click the ellipsis to the right of the target branch and select Branch Security and then make sure that the build account has permissions:

enter image description here

4
Hank On

Make sure that the build service is the one you expect. I tried to reproduce this and was able to at first. I was following these instructions on granting version control permissions to the build service.

Got the same error as you:

Azure DevOps Pipline failure showing same error as OP

TF401027: You need the Git 'GenericContribute' permission to perform this action. Details: identity 'Build\2e5d905b-bbb1-49b6-bffe-540999a98f35', scope 'repository'

What I did next is confirmed that the GUID I got here was the same as the Project Collection Build Service ({organization}) as mentioned in the instructions above. You can do this by grabbing all the users via the Graph API: https://vssps.dev.azure.com/{organization}/_apis/graph/users?api-version=7.1-preview.1

However, I found that the GUID instead belonged to the {Project Name} Build Service ({organization}).

GUID of user indicates it parts of project service

When I changed the permissions to that service, then it succeeded.

enter image description here enter image description here