使用自托管代理解压缩时,GitHub 操作签出失败

问题描述

我正在使用 GitHub Actions 和安装在 Windows 2019 服务器上的自托管代理设置 CI/CD 管道。

我面临的问题是操作 actions/checkout@v2 无法检出 repo 并完全解压缩它。当我说“完全解压缩”时,我的意思是目标文件夹中有一些文件在停止之前设法解压缩。

来自日志:

Run actions/checkout@v2
Syncing repository: Syd/ExternWebb
Getting Git version info
Deleting the contents of 'C:\actions-runner\_work\ExternWebb\ExternWebb'
The repository will be downloaded using the GitHub REST API
To create a local Git repository instead,add Git 2.18 or higher to the PATH
Downloading the archive
Writing archive to disk
Extracting the archive
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Nologo -Sta -noprofile -NonInteractive -ExecutionPolicy Unrestricted -Command "$ErrorActionPreference = 'Stop' ; try { Add-Type -AssemblyName System.IO.Compression.FileSystem } catch { } ; [System.IO.Compression.ZipFile]::ExtractToDirectory('C:\actions-runner\_work\ExternWebb\ExternWebb\b3193a49-e100-4cbd-81c9-6bd23ff47313.tar.gz','C:\actions-runner\_work\ExternWebb\ExternWebb\b3193a49-e100-4cbd-81c9-6bd23ff47313')"
Exception calling "ExtractToDirectory" with "2" argument(s): "Could not find a part of the path 'C:\actions-runner\_wor
k\ExternWebb\ExternWebb\b3193a49-e100-4cbd-81c9-6bd23ff47313\Syd-ExternWebb-77d0427f54bc3e4d6694
f0719ca9fe3ab3be3706\ExternWebb.Library\Custom\Plugins\DomainRedirectModule\DomainRedirectConfigurationCollection
.cs'."
At line:1 char:111
+ ... catch { } ; [System.IO.Compression.ZipFile]::ExtractToDirectory('C:\a ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [],ParentContainsErrorRecordException
    + FullyQualifiedErrorId : DirectoryNotFoundException
 
Error: The process 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' Failed with exit code 1

我试过在本地自托管代理上运行相同的操作,没有任何问题。

reddit post 建议通过 Git 获取 repo 可以减轻错误,并在日志中指向此线索:

The repository will be downloaded using the GitHub REST API
To create a local Git repository instead,add Git 2.18 or higher to the PATH

我尝试安装 Git v.2.30 并按照上述说明将其添加到 PATH,但出于某种原因,该操作仍会通过 GIT API 下载存储库。我不知道是否需要重启服务器,但 git 命令在 Powershell 中可用。

我猜这就是为什么本地自托管代理(可以访问 GIT)可以检查存储库,而在服务器上运行的代理不能。

这是工作流 yml 文件

name: Build Stage

on:
  push:
    branches: [ develop ]
  pull_request:
    branches: [ develop ]

jobs:
  build:
    runs-on: [self-hosted,stage]
    env:
      CONfig: Stage
      BUILD_FOLDER: _build
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      
    steps:
    - name: Checking out source code
      uses: actions/checkout@v2

任何见解都得到了应用。

解决方法

确保在安装 Git 后停止并重新启动 GitHub Actions Runner 服务。对我来说就是这样。

,

如果 Actions Runner 作为服务托管,则安装 Git 并重新启动 runner PC 就足够了。