Home

powershell to run git commit using PAT in Azure github pipelines

%3CLINGO-SUB%20id%3D%22lingo-sub-1085081%22%20slang%3D%22en-US%22%3Epowershell%20to%20run%20git%20commit%20using%20PAT%20in%20Azure%20github%20pipelines%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1085081%22%20slang%3D%22en-US%22%3E%3CP%3EI%20created%20a%20Personal%20Access%20Token%20for%20my%20repository%20and%20named%20it%20as%20'PAT'%2C%20created%20a%20variable%20called%20'PATSecret'%20in%20my%20pipeline%20for%20the%20secret%20of%20PAT.%20Passing%20PATSecret%20as%20an%20input%20variable%20for%20%24Cred.%20But%20when%20trying%20to%20use%20this%20secret%20to%20run%20commit%20command%2C%20authentication%20is%20failing.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CFONT%20color%3D%22%230000FF%22%3E%3CSPAN%3Eparam%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%20color%3D%22%230000FF%22%3E%3CSPAN%3E%5Bstring%5D%3C%2FSPAN%3E%3CSPAN%3E%24Cred%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%20color%3D%22%230000FF%22%3E%3CSPAN%3E)%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CDIV%3E%3CDIV%3E%3CFONT%20color%3D%22%230000FF%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3Bgit%26nbsp%3B--version%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%20color%3D%22%230000FF%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3Bgit%26nbsp%3Badd%26nbsp%3B.%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%20color%3D%22%230000FF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CSPAN%3EWrite-Host%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%22setup%26nbsp%3Bauthor%26nbsp%3Binfo%22%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%20color%3D%22%230000FF%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3Bgit%26nbsp%3Bconfig%26nbsp%3Buser.email%26nbsp%3Byou%40you.com%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%20color%3D%22%230000FF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CSPAN%3Egit%26nbsp%3Bconfig%26nbsp%3Buser.name%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%22your%26nbsp%3Bname%22%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%20color%3D%22%230000FF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CSPAN%3EWrite-Host%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%22git%26nbsp%3Bcommit%26nbsp%3Bwith%26nbsp%3Bmessage%22%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%20color%3D%22%230000FF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CSPAN%3Egit%26nbsp%3Bcommit%26nbsp%3B-m%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%22Test%26nbsp%3BCommit%26nbsp%3Bfrom%26nbsp%3BAzure%26nbsp%3BDevOps%22%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CFONT%20color%3D%22%230000FF%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CSPAN%3Egit%26nbsp%3Bpush%26nbsp%3B-u%26nbsp%3Bhttps%3A%2F%2FPAT%3A%24(%3C%2FSPAN%3E%3CSPAN%3E%24cred%3C%2FSPAN%3E%3CSPAN%3E)%40dev.azure.com%2Fproject%2F_git%2Fmyrepo%20HEAD%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%3CFONT%20color%3D%22%23FF0000%22%3E%3CU%3EError%20message%3C%2FU%3E%3C%2FFONT%3E%3A%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CDIV%20class%3D%22bolt-fixed-height-list-row%20scroll-hidden%20absolute%20focused%22%3E%3CDIV%20class%3D%22line-row%20flex-row%20flex-grow%22%3E%3CFONT%20color%3D%22%23FF0000%22%3E%3CSPAN%20class%3D%22line-area%20flex-center%20flex-row%20flex-grow%20justify-start%22%3E%3CSPAN%20class%3D%22content%22%3E%3CSPAN%20class%3D%22pl-plain%22%3E%3CSPAN%3Efatal%3A%20Authentication%20failed%20for%20'%3CA%20href%3D%22https%3A%2F%2Fdev.azure.com%2Fproject%2F_git%2Fmyrepo%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdev.azure.com%2Fproject%2F_git%2Fmyrepo%2F%3C%2FA%3E'%20%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CDIV%20class%3D%22bolt-fixed-height-list-row%20scroll-hidden%20absolute%22%3E%3CDIV%20class%3D%22line-row%20flex-row%20flex-grow%22%3E%3CFONT%20color%3D%22%23FF0000%22%3E%3CSPAN%20class%3D%22line-area%20flex-center%20flex-row%20flex-grow%20justify-start%20highlight%22%3E%3CSPAN%20class%3D%22content%22%3E%3CSPAN%20class%3D%22pl-error%22%3E%3CSPAN%3E%23%23%5Berror%5DPowerShell%20exited%20with%20code%20'1'.%20%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1085081%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20DevOps%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Egithub%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Highlighted
New Contributor

I created a Personal Access Token for my repository and named it as 'PAT', created a variable called 'PATSecret' in my pipeline for the secret of PAT. Passing PATSecret as an input variable for $Cred. But when trying to use this secret to run commit command, authentication is failing.

 

param(
[string]$Cred
)
   git --version
   git add .
   Write-Host "setup author info"
   git config user.email you@you.com
   git config user.name "your name"
   Write-Host "git commit with message"
   git commit -m "Test Commit from Azure DevOps"
 
   git push -u https://PAT:$($cred)@dev.azure.com/project/_git/myrepo HEAD
 
 
 
Error message:
fatal: Authentication failed for 'https://dev.azure.com/project/_git/myrepo/'
##[error]PowerShell exited with code '1'.