首页 > 解决方案 > 如何指定 Azure DevOps 构建代理使用的 git 可执行文件

问题描述

我在 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。这实际上可行,但这不是最好的解决方法,我想要一个更干净的解决方案。

标签: gitazureazure-devopsbuild-automationbuild-agent

解决方案


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

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

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

VSTS Git Fetch 失败,退出代码:128

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

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

在此处输入图像描述

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

cd \opt\local\bin

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

希望这可以帮助。


推荐阅读