致命:无法读取“https://[email protected]”的密码:终端提示已禁用

问题描述 投票:0回答:7

在使用 Azure Pipelines PowerShell 任务构建时,我尝试将

develop
分支合并到
master
分支。

但是在执行命令

git push
时,我收到此错误:

致命:无法读取密码 'https://[email protected]':终端提示已禁用

代码存储库是“Azure Repos Git”。

git checkout -b master
git config --global user.email "[email protected]"
git config --global user.name "xxxxx"
git merge origin/develop 
git push origin master

参考了一些网址后,我创建了个人访问令牌,并将推送命令修改为

git push https://[email protected]/OrganizationName
,但仍然不起作用。

如果您找到此问题的解决方案,请告诉我。

git azure-devops azure-pipelines azure-powershell azure-pipelines-build-task
7个回答
26
投票

正如您提到的,您需要使用 PAT,但以这种方式:

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

另一个解决方案是在作业选项中“允许脚本访问 OAuth 令牌”:

在 git Push 中使用 System.AccessToken:

git push https://$env:[email protected]/......

并向构建用户授予推送权限(在存储库设置中):


7
投票

添加结帐作为第一步:


steps:
- checkout: self
  persistCredentials: true

确保设置了 git 配置

git config --global user.email "[email protected]"
git config --global user.name "Your Name"

确保向构建服务授予版本控制权限。

  1. 转到项目设置 --> 存储库菜单 --> 您的存储库 --> 安全选项卡,并向
    Project Collection Build Service ({your organization})
    身份授予以下权限:
  • 创建分支:允许
  • 贡献:允许
  • 阅读:允许
  • 创建标签:允许

您现在应该能够使用 git 命令,而无需手动将访问令牌附加到任何 git 命令中。

更多信息请参见此处:https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/git-commands?view=azure-devops&tabs=yaml


1
投票

类似于 Shayki 的答案,但如果您没有运行 powershell 任务,请使用:

git push https://$(System.AccessToken)@dev.azure.com/......

我特别使用

  • 经典管道
  • 本地 Windows 构建代理
    • 代理作业设置已启用允许脚本访问 OAuth 令牌
  • 命令行任务

1
投票
# Node.js # Build a general Node.js project with npm. # Add steps that analyze code, save build artifacts, deploy, and more: # https://learn.microsoft.com/azure/devops/pipelines/languages/javascript trigger: - master - your-branch-name-here pr: none pool: vmImage: "macos-latest" jobs: - job: Perform_Commit_From_CI steps: - checkout: self persistCredentials: true #Important - Persist creds to run further git command clean: true - task: NodeTool@0 inputs: versionSpec: "16.13.2" displayName: "Install Node.js" - script: | git config --global user.email [email protected] git config --global user.name "Test User" displayName: Configure git - script: | yarn install yarn start NAME_OF_THE_SCRIPT_YOU_WANT_TO_EXECUTE git add -A git commit -m 'Test commit [skip ci]' git push origin HEAD:your-branch-name-here displayName: "Test Script"
这无需 PAT 即可工作。


0
投票
个人访问令牌的替代方法是使用 Git 凭据帮助程序,例如

Git Credential Manager(包含在适用于 Windows 的 Git 中)或 git-credential-azure(包含在多个 Linux 发行版中)。两者都支持对 Azure Repos (dev.azure.com) 进行身份验证。

首次进行身份验证时,帮助程序会打开一个浏览器窗口以进行 Microsoft 登录。后续身份验证是非交互式的。


-1
投票
出现此问题可能是因为您使用的 Azure 存储库是私有存储库。

将项目可见性更改为公开解决了该问题。


-6
投票
删除 C:\program files\Git\dev d 然后重新安装 Microsoft git。

© www.soinside.com 2019 - 2024. All rights reserved.