Forum Discussion
SBVRaja
Jan 01, 2020Copper Contributor
powershell to run git commit using PAT in Azure github pipelines
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...
- Aug 04, 2021Solution:
If you are still looking for a solution, here it is. If you found any alternate solution please feel free to post.
#To identify branch name in which the build pipeline is running
if($env:SYSTEM_PULLREQUEST_SOURCEBRANCH)
{
"This is a PR build"
$branch = ("$env:SYSTEM_PULLREQUEST_SOURCEBRANCH").replace("refs/heads/","")
Write-Host "Branch name is: " $branch
}
elseif($env:BUILD_SOURCEBRANCH)
{
"This is a Non-PR build pipeline run"
$branch = ("$env:BUILD_SOURCEBRANCH").replace("refs/heads/","")
}
Else
{
Exit
}
git checkout $branch
git pull
<#Your code & changes to commig#>
git add .
git config --global user.email "Any email id"
git config --global user.name "Any user name"
git commit -am "commit message [ci skip]" #To skip the automatic trigger of the build use [ci skip]
git push --set-upstream origin $branch
Note: You need to enable the option "Allow scripts to access the OAuth token" on the 'Agent job' of the pipeline under Additional Options
hkarthik_7
Jul 20, 2020Copper Contributor
Hello SBVRaja, Please try to run it locally and check if it is working. Make sure to that you have created a service connection in Azure DevOps. And the other possibility is that it could be due to the url, you can refer the documentation for git push here.