【问题标题】:executing "git pull" in azure DevOps release pipelines results in error -> fatal: could not read Username for在 azure DevOps 发布管道中执行“git pull”会导致错误 -> 致命:无法读取用户名
【发布时间】:2020-09-11 09:48:59
【问题描述】:

问题

我正在尝试通过执行一个 powershell 脚本来通过 Azure Devops 发布管道部署我的代码,该脚本检查主分支并拉入我们的生产服务器:

cd "C:\..."
git checkout master
git pull 

当我尝试执行 git pull 时会产生错误:

fatal: could not read Username for 'https://acino.visualstudio.com': terminal prompts disabled

当我从服务器本身执行脚本时,它可以正常工作。只有当我使用发布管道时它才会失败。

疑难解答

• 错误信息会让我相信执行 git pull 时没有设置用户名,但是如果我在代码中添加以下两行

git config user.name 
git config user.email

我看到打印的用户名和电子邮件地址正确。

• 另一种猜测是它试图从错误的源中提取,因为“https://acino.visualstudio.com”不是我的存储库的 URL。所以我也尝试将存储库名称附加到 git pull

git pull https://URL to my repository
with no luck.

因此,我并不真正了解问题的真正含义。欢迎任何意见、评论、建议。

仅供参考:我知道在发布管道中执行 git pull 可能不是部署代码的标准方式。我还构建了其他更传统的部署管道。但是,由于我们的目录/项目结构,使用 git pull 将是我认为的最佳解决方案。

亲切的问候, 韩宝欣

【问题讨论】:

  • 您好,请问这个问题呢?下面的答案是否解决了您的问题,如果是,您可以Accept it as an Answer,这样它可以帮助遇到相同问题的其他社区成员,我们可以存档这个帖子,谢谢。

标签: git deployment azure-devops azure-pipelines-release-pipeline


【解决方案1】:

你可以使用这种格式的 git pull 命令:

git pull {URL} {remote branch}:{local branch}

在 URL 中插入 PAT 将提供凭据来解决登录问题。您可以手动创建新 PAT 或使用 System.AccessToken(更推荐),我这边的最终格式是:

git pull https://$env:SYSTEM_ACCESSTOKEN@dev.azure.com/{OrgName}/{ProjectName}/_git/{RepoName} master:master

git pull https://{PAT}@dev.azure.com/{OrgName}/{ProjectName}/_git/{RepoName} master:master

看起来你的项目仍然是旧格式xxx.visualstudio.com/...,所以你的最终格式应该是这样的:

git pull https://PAT:{PAT}@xxx.visualstudio.com/{ProjectName}/_git/{RepoName} master:master

git pull https://$env:SYSTEM_ACCESSTOKEN@xxx.visualstudio.com/{ProjectName}/_git/{RepoName} master:master

在 URL 中使用 PAT 或 System.AccessToken,您无需配置用户名和密码。请记住,我们应该启用Allow scripts to access the OAuth token,以便我们可以访问System.AccessToken

【讨论】:

  • @RokBohinc 不客气。如果我的回答有用,您可以通过点击我回答的投票按钮下方的“复选标记”按钮mark it as an answer。在这种情况下,其他人可以直接找到有用的解决方案。谢谢~
【解决方案2】:

请尝试在 git config 中使用System.AccessToken,因为它写的是here

$mods = (git submodule status) | % { ($_.Trim() -split " ")[1] }
$baserepo = ($env:BUILD_REPOSITORY_URI).TrimEnd($env:BUILD_REPOSITORY_NAME)
foreach($mod in $mods)
{
cd $mod
$cmd = 'git config http.' + $baserepo + $mod + '.extraheader "AUTHORIZATION: bearer ' + $env:System_AccessToken + '"'
write $cmd
iex $cmd
cd ..
}

你也可以认为this topic很有用。

【讨论】:

    猜你喜欢
    • 2015-01-25
    • 1970-01-01
    • 2012-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-29
    • 2023-03-08
    相关资源
    最近更新 更多