致命:无法读取“https://OrganizationName@dev.azure.com”的密码:终端提示已禁用

VKD*_*VKD 14 git azure-powershell azure-devops azure-pipelines-build-task azure-pipelines

使用 Azure Pipelines PowerShell 任务构建时,我试图将develop分支合并到分支master

但是在执行命令时git push,我收到此错误:

致命:无法读取“ https://OrganizationName@dev.azure.com ”的密码:终端提示已禁用

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

git checkout -b master
git config --global user.email "xxxxxxx@xxxx.xxx"
git config --global user.name "xxxxx"
git merge origin/develop 
git push origin master
Run Code Online (Sandbox Code Playgroud)

在引用了一些 URL 之后,我创建了个人访问令牌,并将推送命令修改为git push https://PAT@dev.azure.com/OrganizationName,但它仍然无法正常工作。

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

Sha*_*zyk 14

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

git push https://{PAT}@dev.azure.com/{organization}/{project}/_git/{repo-name}
Run Code Online (Sandbox Code Playgroud)

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

照片

在 git push 中使用 System.AccessToken:

git push https://$env:SYSTEM_ACCESSTOKEN@dev.azure.com/......
Run Code Online (Sandbox Code Playgroud)

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

在此处输入图片说明

  • 对于 .yaml 构建管道(当前是 Azure Pipelines 的默认值),设置 `persistCredentials: true`。请参阅 [Checkout](https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema%2Cparameter-schema#checkout) 选项。 (7认同)

Dar*_*ell 8

添加结账作为第一步:


steps:
- checkout: self
  persistCredentials: true

Run Code Online (Sandbox Code Playgroud)

确保你设置了 git 配置

git config --global user.email "you@example.com"
git config --global user.name "Your Name"
Run Code Online (Sandbox Code Playgroud)

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

  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