Azure管道:我越来越致命:无法读取“ https://github.com”的用户名:终端提示已禁用

Mut*_*nam 6 git powershell azure-devops azure-pipelines-build-task azure-pipelines

我在azure构建管道中配置了powershell任务,以将来自dev的更改合并到我的github公共仓库的master中,并将更改推送到master。我正进入(状态

严重:无法读取“ https://github.com ”的用户名:禁用终端提示

注意:

  • 我已经用我的用户名和emailid配置了gitconfig。
  • 当我在文件中进行修改并提交并推送时,git push正常工作,但是当我合并并推送时会抛出此错误
  • 我有足够的特权来推动分支

任何帮助,将不胜感激。如果需要更多信息,请在此线程中进行注释。

这是实际的代码段。

$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;
Run Code Online (Sandbox Code Playgroud)

wot*_*324 7

有一个内置的“服务帐户”,实际上是一个称为PAT的PAT Project Collection Build Service,不要与Project Collection Build Service Accounts group混淆。

来自:https//marcstan.net/blog/2018/08/31/Mirror-github-gitlab-and-VSTS-repositories/

Trivia:如果您不知道“ $ env:SYSTEM_ACCESSTOKEN”是一个PAT(个人/私人访问令牌),它是由构建服务器自动生成的(但默认情况下处于禁用状态),并允许您从内部版本和内部版本对VSTS进行身份验证发布。要启用它,您已经在构建或发行定义中选择了“代理作业”,并选中了“其他选项”下的“允许脚本访问OAuth令牌”复选框。

有两个步骤:

步骤1

为了消除fatal: could not read username for...错误,我们需要允许脚本访问OAuth令牌。如果您使用的是基于YAML的最新Azure管道,则用户界面中的“ 允许脚本访问OAuth令牌 ”选项将大打折扣。微软的答案在这里。在您的YAML文件(azure-pipelines.yml)中,添加:

steps:
- checkout: self
  persistCredentials: true
Run Code Online (Sandbox Code Playgroud)

第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
Run Code Online (Sandbox Code Playgroud)

我们还必须授予它权限。从上面相同的页面。将用户 添加Project Collection Build Service到您的仓库中。

在此处输入图片说明

注意:用户(1),而不是组(2)。

格兰特:

Contribute: Allow
Create Branch: Allow
Create Tag: Allow (Inherited)
Read: Allow (Inherited)

Run Code Online (Sandbox Code Playgroud)

高温超导


小智 6

您遇到的情况并不完全相同,但这是唯一接近我类似情况的帖子,因此我认为值得在此处添加我的解决方案。我在托管的Ubuntu Azure Pipeline中遇到此错误,运行shell命令任务来检出,编辑并推送到git。

尝试使用命令推送时出现错误:

git push
Run Code Online (Sandbox Code Playgroud)

我将命令更改为:

git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" push
Run Code Online (Sandbox Code Playgroud)

$(System.AccessToken)是Azure管道中的预定义变量:https ://docs.microsoft.com/zh-cn/azure/devops/pipelines/build/variables?view=azure-devops&viewFallbackFrom=vsts&tabs =yaml

  • 与使用“System.AccessToken”的命令一起使用的另一个关键项目是,您需要在“作业的其他选项”部分中启用“允许脚本访问 OAuth 令牌”(在您包含的链接中提到)。 (6认同)

Sha*_*zyk 4

我不知道为什么,但是当你在 gitpush之后尝试时merge需要用户名和密码。

Azure DevOps 默认情况下禁用输入凭据的提示,并且您收到错误。

GIT_TERMINAL_PROMPT您可以通过将环境变量设置为来启用提示,1但在构建过程中您无法输入值,并且构建将挂起。

要修复该错误,只需在命令中添加用户名和密码或个人访问令牌 (PAT) git push

git push https://username:password(or PAT)@github.com/username/reponame.git 
Run Code Online (Sandbox Code Playgroud)

替换.https://...origin