Mike
Mike

Reputation: 1170

Azure DevOps Powershell git push command throws "Cannot prompt because terminal prompts have been disabled" security error

In repo-A have an Azure DevOps pipeline which is executing a Powershell script, which in turn does various git commands in order to mirror an external repository and push it to repo-B.

The Powershell script resides on a self-hosted agent:

git clean -ffdx
git clone --bare https://gitrepo.mydomain.com/PROJECT_A/app-name.git
cd app-name.git

git push --mirror https://[email protected]/myorg/MyAdoProject/_git/repo-B

If I manually execute the Powershell script from the command line on the self-hosted agent, the push to repo-B executes without incident. However when running the pipeline from ADO, there is a security issue I can't seem to get around. The error generated when the pipeline hits the git push command is:

fatal: Cannot prompt because terminal prompts have been disabled.
fatal: could not read Password for 'https://[email protected]': terminal prompts disabled

In reading through some other posts and Authenticate with personal access tokens - Azure DevOps, I updated my script to use the method in the Powershell section of the previously mentioned document:

git clean -ffdx
git clone --bare https://gitrepo.mydomain.com/PROJECT_A/app-name.git
cd app-name.git

$MyPat = 'personal access token created in ADO'
$B64Pat = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("$MyPat"))
git -c http.extraHeader="Authorization: Basic $B64Pat" push --mirror https://[email protected]/myorg/MyAdoProject/_git/repo-B

However this does not fix the problem and generates the same error as above.

Can anyone recommend what else I might try to get the needed authorization to repo-B when executing from the ADO pipeline?

Upvotes: 2

Views: 5955

Answers (1)

Mike
Mike

Reputation: 1170

The issue was resolved by a combination of two things (refer to this question for further detail):

  1. Adding a Personal Access Token with the Code Read & Write permission enabled

  2. Using the PAT in the url of the git push:

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

Upvotes: 0

Related Questions