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

GitHub Actions中core.setOutput无法生成输出的问题求助

解决GitHub Actions github-script@v6无法获取输出的问题

你的问题出在github-script@v6的输出机制变更上——直接用core.setOutput不会把值暴露为步骤的outputs,得用以下两种方式之一:

方式一:使用github.setOutput设置多输出

github-script提供了专属的github.setOutput方法,专门用来绑定步骤输出,支持设置多个变量:

- uses: actions/github-script@v6
  id: hello-world
  with:
    script: |
      github.setOutput('MY_OUTPUT', 'hello world')
      github.setOutput('ANOTHER_OUTPUT', 'foo bar')
- name: Use outputs
  run: |
    echo "First output: ${{ steps.hello-world.outputs.MY_OUTPUT }}"
    echo "Second output: ${{ steps.hello-world.outputs.ANOTHER_OUTPUT }}"

方式二:返回对象映射多输出

如果更倾向于用返回值的方式,直接返回一个键值对对象即可,github-script会自动把对象的每个键转为步骤的输出项:

- uses: actions/github-script@v6
  id: hello-world
  with:
    script: |
      return {
        MY_OUTPUT: 'hello world',
        ANOTHER_OUTPUT: 'foo bar'
      }
- name: Use outputs
  run: |
    echo "First output: ${{ steps.hello-world.outputs.MY_OUTPUT }}"
    echo "Second output: ${{ steps.hello-world.outputs.ANOTHER_OUTPUT }}"

为什么之前的core.setOutput无效?

github-script@v6之后,步骤的outputs只识别脚本返回值或github.setOutput设置的内容。core.setOutput仅能设置环境变量,不会被该步骤捕获为outputs属性,所以后续步骤无法通过steps.xxx.outputs读取到。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 23:29:55