I have powershell task configured in azure build pipelines to merge changes from dev into master of my github public repo and push changes to master. I am getting
There is a built-in "service account" which is actually a PAT called Project Collection Build Service
, not to be confused with Project Collection Build Service Accounts
group.
From: https://marcstan.net/blog/2018/08/31/Mirror-github-gitlab-and-VSTS-repositories/
Trivia: In case you didn't know "$env:SYSTEM_ACCESSTOKEN" is a PAT (Personal/Private Access Token) that is auto generated by the build server (but disabled by default) and allows to authenticate against VSTS from inside your builds and releases. To enable it, you have select the "agent job" inside your build or release definition and check the "Allow scripts to access the OAuth token" checkbox under "Additional options".
There are two steps to this:
To get rid of the fatal: could not read username for...
error, we need to allow scripts to access the OAuth token. If you're using the newest YAML-based Azure Pipeline, you'll be hunting high and low for "Allow scripts to access the OAuth token" option in the UI. The Microsoft answer is here. In your YAML file (azure-pipelines.yml
), add:
steps:
- checkout: self
persistCredentials: true
After resolving the OP's error, I couldn't commit, receiving the error:
remote: 001f# service=git-receive-pack
remote: 0000000000aaTF401027: You need the Git 'GenericContribute' permission to perform this action. Details: identity 'Build\c21ba3ac-5ad4-de50-bc1a-12ee21de21f0', scope 'repository'.
remote: TF401027: You need the Git 'GenericContribute' permission to perform this action. Details: identity 'Build\c21ba3ac-5ad4-de50-bc1a-12ee21de21f0', scope 'repository'.
fatal: unable to access 'https://[username].visualstudio.com/[repo]/_git/[repo]/': The requested URL returned error: 403
We also have to give it permissions. From the same page as above. Add the user Project Collection Build Service
to your repo(s).
Note: The user (1) and not the group (2).
Grant:
Contribute: Allow
Create Branch: Allow
Create Tag: Allow (Inherited)
Read: Allow (Inherited)
HTH