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

如何在Windows自托管运行器中使用复合自定义Action?

解决Windows自托管运行器调用复合自定义Action的问题

1. 修复自定义Action的YAML语法错误

你遇到的第一个解析错误(Mapping values are not allowed in this context),核心原因是自定义Action的YAML文件缩进不符合规范。YAML对层级缩进要求严格,你的run字段缩进位置错误,导致解析器无法识别正确的映射结构。

修正后的action.yml内容如下:

name: "Composite action Test"

runs:
  using: "composite"
  steps:
    - name: step 1
      run: |
        Write-Host "Hello"
      shell: pwsh

    - name: step 2
      run: |
        Write-Host "world"
      shell: pwsh
  • 每个step的name、run、shell字段需保持同一缩进级别(通常为2个空格)
  • 添加shell: pwsh明确指定使用PowerShell执行命令,避免Windows默认CMD环境的兼容性问题

2. 工作流中使用正确的相对路径

在Windows自托管运行器上,GitHub Actions仍要求使用正斜杠作为路径分隔符,反斜杠和绝对路径都会触发the 'uses' attribute must be a path...错误。

工作流文件中保持以下写法即可:

steps:
  - name: Checkout repository
    uses: actions/checkout@v3

  - name: Execute custom action
    uses: ./.github/actions/my-custom-action/

也可以省略末尾的斜杠:

uses: ./.github/actions/my-custom-action

3. 验证要点

  • 确保actions/checkout@v3步骤已成功将仓库代码拉取到运行器的工作目录
  • 确认自定义Action的路径相对于工作目录存在:.github/actions/my-custom-action/action.yml
  • 修复YAML缩进后,运行器可正确解析自定义Action的配置逻辑

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 13:47:24