I am able to clone the Devops Repo via PAT toke in below way :
git clone https://<>@dev.azure.com/organisation/project/_git/myGitRepo
But I am trying to clone the repo via Service principal for which I am using the below logic :
$resource="499b84ac-1321-427f-aa17-267ca6975798"
$TenantId=" "
$ClientId=" "
$ClientSecret=" "
$TokenUri = "https://login.microsoftonline.com/$TenantID/oauth2/token/"
$Body = "client_id=$ClientId&client_secret=$ClientSecret&resource=$Resource&grant_type=client_credentials"
$TokenResult = Invoke-RestMethod -Uri $TokenUri -Body $Body -Method "POST"
$AccesToken = $TokenResult.access_token
$URI= "https://[email protected]/organisation/project/_git/myGitRepo"
git clone $URI
I am getting the below error :
remote: TF401019: The Git repository with name or identifier myGitRepo does not exist or you do not have permissions for
the operation you are attempting.
fatal: repository ‘https://dev.azure.com/organisation/project/_git/myGitRepo/’ not found
Note :
The service principal is added as a Project administrator within the Devops Project and Stakeholder access level at Organization level