You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Actions自托管Runner报错:pwsh命令未找到(Win10环境)

问题:Win10自托管GitHub Actions Runner执行pwsh步骤报错"pwsh: command not found"

在Win10机器上通过命令提示符运行GitHub Actions自托管Runner,使用以下工作流:

name: Release New NuGet Package Test

on:
  workflow_dispatch:
    inputs:
      nugetPkgProjectName:
        description: 'Enter your NuGet Package Project Name:'
        required: true
        type: string
      incrementMinorVersion:
          description: 'Set to "true" if you want to increment minor and set patch to zero.'
          required: false
          type: string
      descriptionVar:
          description: 'What changes were made in this version?'
          required: false
          type: string

jobs:
  begin:
    runs-on: martin-laptop
    steps:
        - uses: actions/checkout@v3
          with:
            sparse-checkout: |
              Martin Nuget Work

        - name: Extract Branch and Commit
          run: |
            echo "Branch = ${{ github.ref_name }}"
            echo "Commit = ${{ github.sha }}"

        - name: Determine NuGet Package Version
          id: run-ps-script
          shell: pwsh
          run: |
            Write-Host "here is some pwsh stuff"
            Write-Host "cool env var : $env:GITHUB_ACTION_PATH/Martin Nuget Work"

触发工作流后,在Determine NuGet Package Version步骤中报错:

Run Write-Host "here is some pwsh stuff"
  Write-Host "here is some pwsh stuff"
  Write-Host "cool env var : $env:GITHUB_ACTION_PATH/Martin Nuget Work"
  Error: pwsh: command not found

该工作流此前可正常运行,但在新机器上始终无法执行pwsh步骤,请问是否是Runner的问题?


解决方案

这个报错核心是新机器找不到pwsh可执行文件,和Runner本身关联不大,主要是机器PowerShell环境配置问题,按以下步骤排查:

  • 确认PowerShell 7是否安装
    GitHub Actions中shell: pwsh指定的是PowerShell 7及以上版本,不是Windows默认的Windows PowerShell(5.x)。新机器可能只装了旧版,需安装PowerShell 7,安装时务必勾选「将PowerShell添加到系统PATH」选项。

  • 检查系统PATH环境变量
    打开命令提示符输入pwsh,如果提示找不到命令,说明pwsh.exe的路径没加入PATH。PowerShell 7默认路径是C:\Program Files\PowerShell\7,手动将该路径添加到系统PATH后,重启Runner服务(或重启命令提示符后重新启动Runner)。

  • 验证Runner运行权限
    确保以管理员身份在命令提示符中启动自托管Runner,避免权限不足导致PATH读取不全。更新PATH后必须重启Runner,让它加载新的环境变量。

  • 临时替代方案
    如果暂时无法安装PowerShell 7,可以将步骤中的shell: pwsh改为shell: powershell,调用Windows默认的Windows PowerShell,但要注意脚本语法兼容性(比如部分环境变量或命令在旧版中的支持情况)。


内容的提问来源于stack exchange,提问作者POVR2

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 13:05:20