1

Problem

I am trying to deploy my code through a Azure Devops release pipeline by executing a powershell script which checkouts the master branch and pulls on our productive server:

cd "C:\..."
git checkout master
git pull 

this produces an error when I am trying to execute git pull:

fatal: could not read Username for 'https://acino.visualstudio.com': terminal prompts disabled

The script works without a problem when I execute it from the server itself. It fails only when I use the release pipeline.

Troubleshooting

• The error message would let me believe that the user name is not set when executing git pull, However if I add the following two lines to the code

git config user.name 
git config user.email

I see the correct user name and email address being printed.

• The other guess is that it is trying to pull from the wrong origin, since 'https://acino.visualstudio.com' is not the URL of my repository. So I have tried also to append the repository name to git pull

git pull https://URL to my repository
with no luck.

I am therefore don't really understand what the problem is really. Any input, comment,suggestion is welcome.

FYI: I am aware that executing git pull in a release pipeline is not perhaps the standard way of deploying code. I have also build other more conventional deployment pipelines which work. However, due to our directory/project structure using git pull would be optimal solution as I see it.

Kind Regards, Rok Bohinc

Rok Bohinc
  • 47
  • 6
  • Hi, how about the issue? Does the answer below resolve your question, If yes, you could [Accept it as an Answer](https://meta.stackexchange.com/a/5235/515442) , so it could help other community members who get the same issues and we could archive this thread, thanks. – LoLance Sep 16 '20 at 10:04

2 Answers2

2

You can use git pull command with this format:

git pull {URL} {remote branch}:{local branch}

And inserting PAT into the URL would provide credentials to resolve login issues. You can create a new PAT manually or use the System.AccessToken (more recommended), the final format on my side would be:

git pull https://$env:SYSTEM_ACCESSTOKEN@dev.azure.com/{OrgName}/{ProjectName}/_git/{RepoName} master:master

git pull https://{PAT}@dev.azure.com/{OrgName}/{ProjectName}/_git/{RepoName} master:master

It looks your project is still the old format xxx.visualstudio.com/..., so your final formats would be something like:

git pull https://PAT:{PAT}@xxx.visualstudio.com/{ProjectName}/_git/{RepoName} master:master

git pull https://$env:SYSTEM_ACCESSTOKEN@xxx.visualstudio.com/{ProjectName}/_git/{RepoName} master:master

With PAT or System.AccessToken in URL, you don't need to config the username and password. Just remember we should enable Allow scripts to access the OAuth token so that we can access System.AccessToken.

LoLance
  • 25,666
  • 1
  • 39
  • 73
  • @RokBohinc You're welcome. If my answer is useful, you could [mark it as an answer](https://meta.stackexchange.com/a/5235/515442) via clicking the "check mark" button underneath the vote buttons of my answer. In this case, others could directly find the useful solution. Thanks~ – LoLance Sep 14 '20 at 09:22
0

Please try use System.AccessToken in git config as it written here

$mods = (git submodule status) | % { ($_.Trim() -split " ")[1] }
$baserepo = ($env:BUILD_REPOSITORY_URI).TrimEnd($env:BUILD_REPOSITORY_NAME)
foreach($mod in $mods)
{
cd $mod
$cmd = 'git config http.' + $baserepo + $mod + '.extraheader "AUTHORIZATION: bearer ' + $env:System_AccessToken + '"'
write $cmd
iex $cmd
cd ..
}

enter image description here

You can also consider this topic useful.

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107