我在azure构建管道中配置了powershell任务,将dev中的更改合并到我的github公共仓库的主服务器中,并将更改推送到master。我正进入(状态
致命:无法读取'https://github.com'的用户名:终端提示被禁用
注意:
任何有关这方面的帮助将非常感激。如果需要更多信息,请在此主题中发表评论。
这是实际的片段。
$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;
我不知道为什么但是当你在push
git之后尝试merge
时想要用户名和密码。
默认情况下,Azure DevOps禁用输入凭据的提示,但您收到错误。
您可以通过将环境变量GIT_TERMINAL_PROMPT
设置为1
来启用提示,但在构建期间,您无法输入值,构建将挂起。
要修复错误,只需在git push
命令中添加用户名和密码或个人访问令牌(PAT):
git push https://username:password(or PAT)@github.com/username/reponame.git
https://...
取代了origin
。
不是完全相同的情况,但这是我的类似情况接近的唯一帖子所以我认为值得在这里添加我的解决方案。我在托管的Ubuntu Azure管道中遇到此错误,运行shell命令任务来检出,编辑和推送到git。
尝试使用命令时,我收到错误:
git push
我通过将命令更改为:
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" push
$(System.AccessToken)是Azure管道中的预定义变量:https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&viewFallbackFrom=vsts&tabs=yaml
有一个内置的“服务帐户”,实际上是一个名为Project Collection Build Service
的PAT,不要与Project Collection Build Service Accounts
组混淆。
来自:https://marcstan.net/blog/2018/08/31/Mirror-github-gitlab-and-VSTS-repositories/
琐事:如果您不知道“$ env:SYSTEM_ACCESSTOKEN”是由构建服务器自动生成的PAT(个人/私有访问令牌)(但默认情况下已禁用),并允许从构建内部对VSTS进行身份验证,版本。要启用它,您必须在构建或发布定义中选择“代理作业”,然后选中“其他选项”下的“允许脚本访问OAuth令牌”复选框。
这有两个步骤:
要摆脱fatal: could not read username for...
错误,我们需要允许脚本访问OAuth令牌。如果您使用的是最新的基于YAML的Azure管道,那么您将在UI中“允许脚本访问OAuth令牌”选项的高低。微软的答案是here。在您的YAML文件(azure-pipelines.yml
)中,添加:
steps:
- checkout: self
persistCredentials: true
解决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。将用户Project Collection Build Service
添加到您的仓库。
注意:用户(1)而不是组(2)。
格兰特:
Contribute: Allow
Create Branch: Allow
Create Tag: Allow (Inherited)
Read: Allow (Inherited)
HTH