Azure DevOps 专用 Linux 代理 - YAML 管道签出失败 - 可以使用"git config --global --unset http.extraHeader"修复,但不够早



我们有一个关于以下内容的问题:

  • Azure DevOps Linux专用代理

  • 损坏/过时的承载令牌可能存在问题

  • 可以通过登录到框中使用此命令进行修复,但这并不方便:git config --global --unset http.extraHeader

  • 可以将此命令作为YAML:git config --global --unset http.extraHeader中脚本的一部分进行修复,但还不够早。(请参阅下面的下一条评论(。

  • 我无法在管道YAML中尽早运行此命令来清除标头,因为签出不受我控制。

  • 通常只有在前一次运行在同一个专用代理上的某个时刻失败时才会发生这种情况

    Syncing repository: test-project-azure-workspace (Git)
    git version
    git version 2.26.0
    git lfs version
    git-lfs/2.10.0 (GitHub; linux amd64; go 1.13.4)
    git config --get remote.origin.url
    git clean -ffdx
    git reset --hard HEAD
    HEAD is now at 5f9fd24 sql mi
    git config gc.auto 0
    git config --get-all http.https://xxxxxxx@dev.azure.com/xxxxxxx/xxxxxxx/_git/test-project-azure-workspace.extraheader
    git config --get-all http.proxy
    git config http.version HTTP/1.1
    git -c http.extraheader="AUTHORIZATION: bearer ***" -c http.proxy="http://10.XXX.XXX.XX:80" fetch --force --tags --prune --progress --no-recurse-submodules --unshallow origin
    * Couldn't find host dev.azure.com in the .netrc file; using defaults
    

以下是可以补救症状的代码:

- script: |
echo '======================================================================'
echo 'list all of git config values for your convenience:'
echo '======================================================================'
git config --list 
echo '======================================================================'
existing_header=$(git config  --get http.extraHeader)
if [ ${#existing_header} -gt 0 ]
then  
echo 'We found the http.extraHeader'
echo 'un-setting extra header: http.extraHeader 🔥'
git config --global --unset http.extraHeader
else
echo 'no extra header: http.extraHeader was not found. Nothing to unset 👍'
fi
condition: always() 
workingDirectory: '$(Agent.BuildDirectory)/s'
displayName: 'Remove Git Authentication'

显然,我是在治疗症状,而不是病因,所以任何关于病因的线索都将是一个很大的帮助。

您可以创建一个;清洁";作业,该作业使用带有nonecheckout任务作为要签出的repo。这将允许您运行清理脚本。

- job: cleanAgent
steps: 
- checkout: none
- script: |
echo "Put your git cleaner here"

一个更好的选择是在完成后通过在管道末端运行条件为always()的清理任务来清理代理。如果其他人也使用这些药剂,但不进行清理,这可能会很困难。

- job: cleanupAgents
condition: always()
steps:
- script: |
echo "Put your git cleaner here"

最新更新