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

GitHub Action中后续Job获取前一Job输出值为空求助

问题排查与解决

你的问题出在环境变量语法不匹配运行系统:Job运行在CentOS7(Linux)环境,但步骤里用了Windows PowerShell的环境变量写法$env:GITHUB_OUTPUT,Linux系统下需用$GITHUB_OUTPUT来引用该环境变量,导致输出未正确写入,后续Job读取为空。

修正后的完整Workflow配置

on: pull_request

jobs:
  job1:
    runs-on: [re-centos7]
    outputs:
      output1: ${{ steps.step1.outputs.test }}
      output2: ${{ steps.step2.outputs.test }}
    steps:
      - id: step1
        run: echo "test=world1" >> $GITHUB_OUTPUT
      - id: step2
        run: echo "test=world" >> $GITHUB_OUTPUT
  job2:
    runs-on: [re-centos7]
    needs: job1
    steps:
      - run: echo ${{needs.job1.outputs.output1}}

关键说明

GitHub Actions中,不同系统的环境变量引用规则不同:

  • Linux/macOS环境:用$变量名格式(如$GITHUB_OUTPUT)
  • Windows PowerShell环境:用$env:变量名格式(如$env:GITHUB_OUTPUT)

你的Runner基于CentOS7(Linux),必须使用Linux语法才能正确将输出写入GITHUB_OUTPUT文件,后续Job才能读取到传递的值。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 21:15:32