Azure Pipelines:我越来越致命:无法读取 'https://github.com' 的用户名:终端提示已禁用
Azure Pipelines: I am getting fatal: could not read Username for 'https://github.com': terminal prompts disabled
我在 azure 构建管道中配置了 powershell 任务,将 dev 的更改合并到我的 github public 存储库的 master 中,并将更改推送到 master。我得到
fatal: could not read Username for 'https://github.com': terminal prompts disabled
注:
- 我已经用我的用户名和电子邮件 ID 配置了我的 gitconfig。
- 当我修改文件并提交和推送时,git 推送工作正常,但当我合并和推送时它抛出此错误
- 我有足够的权限推入分支
如有任何帮助,我们将不胜感激。如果需要更多信息,请在此线程中发表评论。
这是实际的片段。
$branchName = $env:BRANCH_NAME;
Write-Host "Getting SHA for last commit in the latest release" -ForegroundColor Blue;
$latestReleaseCommitSHA = git rev-list --tags --max-count=1;
if([string]::IsNullOrEmpty($latestReleaseCommitSHA)) {
Write-Host "Unable to get the SHA for last commit in latest release" -ForegroundColor Red;
EXIT 1;
}
Write-Host "SHA for last commit in the latest release is '$($latestReleaseCommitSHA)'" -ForegroundColor Green;
Write-Host "Merging Changes till '$($latestReleaseCommitSHA)'" -ForegroundColor Blue;
git merge $latestReleaseCommitSHA
Write-Host "Checking Conflicted Files";
$conflictedFiles = git diff --name-only --diff-filter=U
if (-Not [string]::IsNullOrEmpty($conflictedFiles)) {
Write-Host "Unable to Merge" -ForegroundColor Red;
Write-Host "There are conflicts in below files:" -ForegroundColor Cyan;
Write-Host -Object $conflictedFiles -ForegroundColor Cyan;
EXIT 1;
}
Write-Host "Merged changes to '$($branchName)'" -ForegroundColor Green;
Write-Host "Pushing changes." -ForegroundColor Blue;
git push origin HEAD:$branchName
Write-Host "Pushed the changes to the $($branchName) branch." -ForegroundColor Green;
我不明白为什么,但是当你在 merge
git 之后尝试 push
时想要用户名和密码。
默认情况下,Azure DevOps 禁用输入凭据的提示,您遇到了错误。
您可以通过将环境变量 GIT_TERMINAL_PROMPT
设置为 1
来启用提示,但在构建过程中您无法输入值,构建将挂起。
要修复错误,只需在 git push
命令中添加用户名和密码或个人访问令牌 (PAT):
git push https://username:password(or PAT)@github.com/username/reponame.git
https://...
替换origin
.
与您遇到的情况不完全相同,但这是唯一 post 与我的类似情况接近的情况,因此我认为值得在此处添加我的解决方案。我在托管的 Ubuntu Azure Pipeline 中遇到了这个错误,运行 一个 shell 命令任务来检出、编辑并推送到 git.
尝试使用命令推送时出现错误:
git push
我通过将命令更改为:
来修复它
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" push
$(System.AccessToken) 是 Azure Pipelines 中的预定义变量:
https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&viewFallbackFrom=vsts&tabs=yaml
有一个built-in“服务帐户”,它实际上是一个名为Project Collection Build Service
的PAT,不要与Project Collection Build Service Accounts
组混淆.
发件人:https://marcstan.net/blog/2018/08/31/Mirror-github-gitlab-and-VSTS-repositories/
Trivia: In case you didn't know "$env:SYSTEM_ACCESSTOKEN" is a PAT (Personal/Private Access Token) that is auto generated by the build server (but disabled by default) and allows to authenticate against VSTS from inside your builds and releases. To enable it, you have select the "agent job" inside your build or release definition and check the "Allow scripts to access the OAuth token" checkbox under "Additional options".
这有两个步骤:
步骤 1
要消除 fatal: could not read username for...
错误,我们需要允许脚本访问 OAuth 令牌。如果您使用的是最新的 YAML-based Azure Pipeline,您将在 [=55= 中寻找“允许脚本访问 OAuth 令牌”选项。 ].微软的答案是 here。在您的 YAML 文件 (azure-pipelines.yml
) 中,添加:
steps:
- checkout: self
persistCredentials: true
第 2 步
解决OP的错误后,我无法提交,收到错误:
remote: 001f# service=git-receive-pack
remote: 0000000000aaTF401027: You need the Git 'GenericContribute' permission to perform this action. Details: identity 'Build\c21ba3ac-5ad4-de50-bc1a-12ee21de21f0', scope 'repository'.
remote: TF401027: You need the Git 'GenericContribute' permission to perform this action. Details: identity 'Build\c21ba3ac-5ad4-de50-bc1a-12ee21de21f0', scope 'repository'.
fatal: unable to access 'https://[username].visualstudio.com/[repo]/_git/[repo]/': The requested URL returned error: 403
我们还必须给它权限。从 same page 如上。将 user Project Collection Build Service
添加到您的存储库中。
注意:用户 (1) 而不是组 (2)。
授予:
Contribute: Allow
Create Branch: Allow
Create Tag: Allow (Inherited)
Read: Allow (Inherited)
HTH
我在 azure 构建管道中配置了 powershell 任务,将 dev 的更改合并到我的 github public 存储库的 master 中,并将更改推送到 master。我得到
fatal: could not read Username for 'https://github.com': terminal prompts disabled
注:
- 我已经用我的用户名和电子邮件 ID 配置了我的 gitconfig。
- 当我修改文件并提交和推送时,git 推送工作正常,但当我合并和推送时它抛出此错误
- 我有足够的权限推入分支
如有任何帮助,我们将不胜感激。如果需要更多信息,请在此线程中发表评论。
这是实际的片段。
$branchName = $env:BRANCH_NAME;
Write-Host "Getting SHA for last commit in the latest release" -ForegroundColor Blue;
$latestReleaseCommitSHA = git rev-list --tags --max-count=1;
if([string]::IsNullOrEmpty($latestReleaseCommitSHA)) {
Write-Host "Unable to get the SHA for last commit in latest release" -ForegroundColor Red;
EXIT 1;
}
Write-Host "SHA for last commit in the latest release is '$($latestReleaseCommitSHA)'" -ForegroundColor Green;
Write-Host "Merging Changes till '$($latestReleaseCommitSHA)'" -ForegroundColor Blue;
git merge $latestReleaseCommitSHA
Write-Host "Checking Conflicted Files";
$conflictedFiles = git diff --name-only --diff-filter=U
if (-Not [string]::IsNullOrEmpty($conflictedFiles)) {
Write-Host "Unable to Merge" -ForegroundColor Red;
Write-Host "There are conflicts in below files:" -ForegroundColor Cyan;
Write-Host -Object $conflictedFiles -ForegroundColor Cyan;
EXIT 1;
}
Write-Host "Merged changes to '$($branchName)'" -ForegroundColor Green;
Write-Host "Pushing changes." -ForegroundColor Blue;
git push origin HEAD:$branchName
Write-Host "Pushed the changes to the $($branchName) branch." -ForegroundColor Green;
我不明白为什么,但是当你在 merge
git 之后尝试 push
时想要用户名和密码。
默认情况下,Azure DevOps 禁用输入凭据的提示,您遇到了错误。
您可以通过将环境变量 GIT_TERMINAL_PROMPT
设置为 1
来启用提示,但在构建过程中您无法输入值,构建将挂起。
要修复错误,只需在 git push
命令中添加用户名和密码或个人访问令牌 (PAT):
git push https://username:password(or PAT)@github.com/username/reponame.git
https://...
替换origin
.
与您遇到的情况不完全相同,但这是唯一 post 与我的类似情况接近的情况,因此我认为值得在此处添加我的解决方案。我在托管的 Ubuntu Azure Pipeline 中遇到了这个错误,运行 一个 shell 命令任务来检出、编辑并推送到 git.
尝试使用命令推送时出现错误:
git push
我通过将命令更改为:
来修复它git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" push
$(System.AccessToken) 是 Azure Pipelines 中的预定义变量: https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&viewFallbackFrom=vsts&tabs=yaml
有一个built-in“服务帐户”,它实际上是一个名为Project Collection Build Service
的PAT,不要与Project Collection Build Service Accounts
组混淆.
发件人:https://marcstan.net/blog/2018/08/31/Mirror-github-gitlab-and-VSTS-repositories/
Trivia: In case you didn't know "$env:SYSTEM_ACCESSTOKEN" is a PAT (Personal/Private Access Token) that is auto generated by the build server (but disabled by default) and allows to authenticate against VSTS from inside your builds and releases. To enable it, you have select the "agent job" inside your build or release definition and check the "Allow scripts to access the OAuth token" checkbox under "Additional options".
这有两个步骤:
步骤 1
要消除 fatal: could not read username for...
错误,我们需要允许脚本访问 OAuth 令牌。如果您使用的是最新的 YAML-based Azure Pipeline,您将在 [=55= 中寻找“允许脚本访问 OAuth 令牌”选项。 ].微软的答案是 here。在您的 YAML 文件 (azure-pipelines.yml
) 中,添加:
steps:
- checkout: self
persistCredentials: true
第 2 步
解决OP的错误后,我无法提交,收到错误:
remote: 001f# service=git-receive-pack
remote: 0000000000aaTF401027: You need the Git 'GenericContribute' permission to perform this action. Details: identity 'Build\c21ba3ac-5ad4-de50-bc1a-12ee21de21f0', scope 'repository'.
remote: TF401027: You need the Git 'GenericContribute' permission to perform this action. Details: identity 'Build\c21ba3ac-5ad4-de50-bc1a-12ee21de21f0', scope 'repository'.
fatal: unable to access 'https://[username].visualstudio.com/[repo]/_git/[repo]/': The requested URL returned error: 403
我们还必须给它权限。从 same page 如上。将 user Project Collection Build Service
添加到您的存储库中。
注意:用户 (1) 而不是组 (2)。
授予:
Contribute: Allow
Create Branch: Allow
Create Tag: Allow (Inherited)
Read: Allow (Inherited)
HTH