<p>I've had a similar issue with git commands in Azure Pipelines.  The reason is that any commands that access the origin server, such as <code>git push</code> need to done by a user that has the credentials to do so.  In your situation, your PowerShell script is running in the user context of <code>Project Collection Build Service (yourProjectName)</code> and it does not have the permissions to contribute to your repo by default.</p>

<p>See this answer, I think it will fix you up: <a href="https://stackoverflow.com/a/56542631/11767897">https://stackoverflow.com/a/56542631/11767897</a></p>

CC BY-SA 4.0
2019-07-29T21:14:33.707Z
2019-07-29T21:14:33.707Z
Michael Erpenbeck
<p>I'm trying to achieve the following through the build pipeline.</p>

<ul>
<li>Default branch: SIT (from the Azure Repos repository)</li>
<li>Trigger: whenever a change is made in DEV branch</li>
</ul>

<p>In a powershell task do the following:</p>

<ul>
<li>Merge latest from DEV to the current SIT branch</li>
<li>Deploy the latest from SIT branch</li>
<li>Push the updated SIT branch to the upstream repository</li>
</ul>

<p>Here is my code:</p>

<pre><code>git checkout -b temp
git merge origin/DEV
git branch -f SIT temp
git checkout SIT
git status
git branch -d temp
git remote add neworigin $(RemoteOrigin)
git push -u origin --all
</code></pre>

<p>When I try to push the updated SIT branch using <code>git push -u origin SIT</code> and I'm getting the following error:</p>

<blockquote>
  <p>remote: 0000000000aaTF401027: You need the Git 'GenericContribute'
  permission to perform this action. Details: identity
  'Build\d073f6c7-4fa2-4bda-8694-8a41fb808fff', scope 'repository'.
  remote: TF401027: You need the Git 'GenericContribute' permission to
  perform this action. Details: identity
  'Build\d073f6c7-4fa2-4bda-8694-8a41fb808fff', scope 'repository'.
  fatal: unable to access '': The requested URL returned
  error: 403</p>
</blockquote>

<p>Can someone help?</p>

<azure-devops><azure-pipelines>
Git Remote Access in Azure Pipelines, possible?
wesfaith
# Git Remote Access in Azure Pipelines, possible?

(Asked by: username_0 on 2019-07-27)

I'm trying to achieve the following through the build pipeline.

Default branch: SIT (from the Azure Repos repository)
Trigger: whenever a change is made in DEV branch

In a powershell task do the following:

Merge latest from DEV to the current SIT branch
Deploy the latest from SIT branch
Push the updated SIT branch to the upstream repository

Here is my code:
git checkout -b temp
git merge origin/DEV
git branch -f SIT temp
git checkout SIT
git status
git branch -d temp
git remote add neworigin $(RemoteOrigin)
git push -u origin --all

When I try to push the updated SIT branch using git push -u origin SIT and I'm getting the following error:

remote: 0000000000aaTF401027: You need the Git 'GenericContribute'
  permission to perform this action. Details: identity
  'Build\d073f6c7-4fa2-4bda-8694-8a41fb808fff', scope 'repository'.
  remote: TF401027: You need the Git 'GenericContribute' permission to
  perform this action. Details: identity
  'Build\d073f6c7-4fa2-4bda-8694-8a41fb808fff', scope 'repository'.
  fatal: unable to access '': The requested URL returned
  error: 403

Can someone help?

**Tags:** azure-devops, azure-pipelines


---

## 1 answers

### Answer by username_1 on 2019-07-29. Score: 1

I've had a similar issue with git commands in Azure Pipelines. The reason is that any commands that access the origin server, such as `git push` need to done by a user that has the credentials to do so. In your situation, your PowerShell script is running in the user context of `Project Collection Build Service (yourProjectName)` and it does not have the permissions to contribute to your repo by default.

See this answer, I think it will fix you up: <https://stackoverflow.com/a/56542631/11767897>


---

