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

无法在Bash脚本中设置GitHub复合Action输出的问题排查

复合Action内Bash脚本设置Action输出无效的问题排查

我在项目中需要在复合Action执行的Bash脚本(goodbye.sh)里设置Action输出,参考GitHub官方文档,得知可通过GITHUB_OUTPUT变量,以echo "{name}={value}" >> $GITHUB_OUTPUT的格式设置输出。

官方提供的复合Action示例中,直接在Action步骤内设置random-number输出可正常工作,示例action.yml代码如下:

name: 'Hello World'
description: 'Greet someone'
inputs:
  who-to-greet:  # id of input
    description: 'Who to greet'
    required: true
    default: 'World'
outputs:
  random-number:
    description: "Random number"
    value: ${{ steps.random-number-generator.outputs.random-number }}
runs:
  using: "composite"
  steps:
    - run: echo Hello ${{ inputs.who-to-greet }}.
      shell: bash
    - id: random-number-generator
      run: echo "random-number=$(echo $RANDOM)" >> $GITHUB_OUTPUT
      shell: bash
    - run: echo "${{ github.action_path }}" >> $GITHUB_PATH
      shell: bash
    - run: goodbye.sh
      shell: bash

对应的测试工作流也能正常运行:

on: [push]

jobs:
  hello_world_job:
    runs-on: ubuntu-latest
    name: A job to say hello
    steps:
      - uses: actions/checkout@v3
      - id: foo
        uses: actions/hello-world-composite-action@v1
        with:
          who-to-greet: 'Mona the Octocat'
      - run: echo random-number ${{ steps.foo.outputs.random-number }}
        shell: bash

但在我的场景中,在goodbye.sh脚本内使用相同方法设置输出却无效,现希望排查是否存在语法问题。

复现步骤

  • Fork目标仓库;
  • 在Fork后的仓库中启用GitHub Actions;
  • 推送一次提交;
  • 查看工作流结果:仅random-number变量正常设置,random-number-bash未生效。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 06:06:45