I have been granted service principal access to my Azure DevOps repository. Below is the script I'm using:
$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://$AccesToken@dev.azure.com/Org/Project/_git/Repo"
git clone $URI "C:\Users\DBT\Desktop\git" cd "C:\Users\DBT\Desktop\git" (Get-Item .).FullName $gitCmd = "git -c http.extraheader='AUTHORIZATION: bearer $AccesToken'" Invoke-Expression "$gitCmd add ." Invoke-Expression "$gitCmd commit -m 'Commit message'" Invoke-Expression "$gitCmd push"
I'm able to successfully clone the repository, but I'm encountering an issue when trying to commit and push changes. The error message I'm receiving is: git: Author identity unknown.
How can I use service principal authentication to commit and push changes to Azure DevOps/Git?