【问题标题】:How can i specify which git executable an Azure DevOps build agent uses如何指定 Azure DevOps 构建代理使用的 git 可执行文件
【发布时间】:2020-09-05 10:43:02
【问题描述】:

由于某些未知原因,我在 Azure DevOps 构建代理上遇到了 git 身份验证问题,身份验证仅适用于 MacPorts 版本的 git:

>/usr/bin/git clone --config "http.sslVerify=false" "https://…:…@…/DefaultCollection/…/_git/…" 
Cloning into '…'...
fatal: Authentication failed for 'https://…:…@…/DefaultCollection/…/_git/…/'

>/usr/local/bin/git clone --config "http.sslVerify=false" "https://…:…@…/DefaultCollection/…/_git/…"
Klone nach '…' ...
fatal: Authentifizierung fehlgeschlagen für 'https://…/DefaultCollection/…/_git/…/'

>/opt/local/bin/git clone --config "http.sslVerify=false" "https://…:…@…/DefaultCollection/…/_git/…" 
Klone nach '…' ...
remote: Azure Repos
remote: Found 25399 objects to send. (22 ms)
Empfange Objekte: 100% (25399/25399), 21.80 MiB | 39.24 MiB/s, Fertig.
Löse Unterschiede auf: 100% (17128/17128), Fertig.

我已经尽力让构建代理使用 MacPorts 版本:

但结帐仍然失败:

##[section]Starting: Checkout
==============================================================================
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
==============================================================================
Syncing repository: repository (ExternalGit)
##[command]git version
git version 2.26.2
##[command]git init "/Work/TFS/1/s"
Leeres Git-Repository in /Users/Shared/Work/TFS/1/s/.git/ initialisiert
##[command]git remote add origin https://…/DefaultCollection/…/_git/…
##[command]git config gc.auto 0
##[command]git config --get-all http.https://…/DefaultCollection/…/_git/….extraheader
##[command]git config --get-all http.proxy
##[command]git remote set-url origin https://***:***@…/DefaultCollection/…/_git/…
##[command]git remote set-url --push origin https://***:***@…/DefaultCollection/…/_git/…
##[command]git -c http.sslVerify=false fetch --force --tags --prune --progress --no-recurse-submodules origin
fatal: Authentifizierung fehlgeschlagen für 'https://…/DefaultCollection/…/_git/…/'
##[warning]Git fetch failed with exit code 128, back off 9.834 seconds before retry.
##[command]git -c http.sslVerify=false fetch --force --tags --prune --progress --no-recurse-submodules origin
fatal: Authentifizierung fehlgeschlagen für 'https://…/DefaultCollection/…/_git/…/'
##[warning]Git fetch failed with exit code 128, back off 8.115 seconds before retry.
##[command]git -c http.sslVerify=false fetch --force --tags --prune --progress --no-recurse-submodules origin
fatal: Authentifizierung fehlgeschlagen für 'https://…/DefaultCollection/…/_git/…/'
##[error]Git fetch failed with exit code: 128
##[section]Finishing: Checkout

那么如何确保使用了正确的 git 可执行文件?我试图搜索管理结帐的脚本,但无济于事。

更新 1: 我已经卸载了 Brew 版本的 Git,但这只会导致使用 macOS 版本。而且我不能卸载那个。

更新 2: 我放置了一个符号链接 ln -s /opt/local/bin/git /usr/local/bin/git。这确实有效,但这不是最好的解决方法,我想要一个更干净的解决方案。

【问题讨论】:

  • 从日志看来,您正在连接到 Azure DevOps 服务器,而不是托管服务。
  • @jessehouwing 是的。请注意,当使用/opt/local/bin/git 时,结帐工作有效。所以这不是一个连接错误。更有可能是 Apple 或 Homebrew 提供的 git 版本存在问题。 MacPorts git 通常是从源代码编译的,因此它可能具有更好的集成性,因此它可以工作。
  • @Martin,看来我们无法将内置任务更改为使用 MacPorts git,我的解决方法如何?对你有帮助吗?

标签: git azure azure-devops build-automation build-agent


【解决方案1】:

如何指定 Azure DevOps 构建代理使用的 git 可执行文件

恐怕我们无法指定 Azure DevOps 构建代理使用哪个 git 可执行文件。那是因为 checkout 任务是一个内置任务,我们无法自定义它以使用其他版本的 git。

首先我们可以尝试缩小这个问题的范围,比如用托管代理检查这个问题,如果这个问题仍然存在,那么这个问题应该与代理无关,请检查我们的权限是否受限:

VSTS Git Fetch Failed with exit code: 128

如果托管代理工作正常,请尝试更新我们的私人代理。

此外,作为一种解决方法,我们可以禁用签出功能并在指定版本中使用 git 手动克隆源代码:

然后,添加命令行或powershell脚本来克隆源代码,如:

cd \opt\local\bin

git clone https://<PAT>@dev.azure.com/<OrganizationName>/MyTestProject/_git/TestSample

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-03
    • 1970-01-01
    • 2019-05-05
    • 2019-11-07
    • 2021-11-18
    • 2021-08-08
    • 2020-03-16
    • 2021-09-21
    相关资源
    最近更新 更多