1

I am executing a batch file in Azure DevOps Pipeline which has following statement.

git init    
git checkout -b %BranchName%    
git remote add origin %RepoURL%    
git fetch && git checkout %BranchName%

The parameters gets the values from Variables. But I am getting the below error.

"Could not read Password for '<Repository URL>': terminal prompts disabled"

I have tried to set the value for the RepoURL parameter as follows.

https://<CollectionName>@dev.azure.com/<CollectionName>/<ProjectName>/_git/<RepoName>
https://<PAT>@dev.azure.com/<CollectionName>/<ProjectName>/_git/<RepoName>

Many post in this forum suggest to use PAT. So tried the git pull statement as follows.

git pull %RepoURL%

But no luck. Still getting the same error. Please anyone let me know how to solve this issue.

Thanks.

VKD
  • 633
  • 2
  • 12
  • 28
  • The accepted answer here: https://stackoverflow.com/a/56734304/2523968 has a top rated comment about the checkout process using what's defined in the documentation here: https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema/steps-checkout?view=azure-pipelines - that should help – Newteq Developer May 02 '23 at 17:04

2 Answers2

3

According to your description, I use the following method for testing, and it works well.

https://{PAT}@dev.azure.com/{organization}/{project}/_git/{repo name}

In order to solve this problem, please check the following things:

1.Enable ‘Allow scripts to access the OAuth token’ in the Agent job options. enter image description here

In the git remote add origin %RepoURL% use the System.AccessToken:

git remote add origin %RepoURL%    
 
RepoURL: https://$env:SYSTEM_ACCESSTOKEN@dev.azure.com/{organization}/{project}/_git/{repo name}
  1. Go to Project Settings-> Repositories under Repos, grant permissions to the build user (in the repo settings). enter image description here
Alina Wang-MSFT
  • 522
  • 3
  • 4
  • Thanks Alina. I am getting the error as "fatal: Authentication failed for 'https://dev.azure.com///_git//'". And FYI I am using Custom Agent Pool Server. But I tried with Microsoft Hosted Agent too. No luck. Please provide some other suggestion – VKD Nov 27 '20 at 08:40
  • Earlier I have tried using Batch Script Task using .bat file. Now I have tried using Powershell task as shown by you. Now I am getting the error as "remote: TF401019: The Git repository with name or identifier does not exist or you do not have permissions for the operation you are attempting.". Any idea? – VKD Nov 27 '20 at 08:59
  • You can try to use the command “git remote rm origin” first to delete the local specified remote address, and then delete the Git credentials in the PC. For more detailed information, please refer to this link: https://stackoverflow.com/questions/17659206/git-push-results-in-authentication-failed https://stackoverflow.com/questions/15381198/remove-credentials-from-git – Alina Wang-MSFT Nov 27 '20 at 09:59
  • In case if we try to access the repo that belongs to different project, any setting needs to be enabled? – VKD Nov 27 '20 at 10:24
2

Could not read Password for 'Repository URL': terminal prompts disabled

If your repo is from another project, you also need to pay attention that you turn off the settings Limit job authorization scope to referenced Azure DevOps repositories:

Project Settings->Settings:

enter image description here

With this option enabled, it reduce the scope of access for all pipelines to only Azure DevOps repositories explicitly referenced by a checkout step in the pipeline job that uses that repository.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135