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

Github Actions中Job B无法识别Job A输出值的问题排查

问题原因及解决办法

你遇到的核心问题是Job A的outputs配置错误,导致Job B无法正确获取到评论ID值。

具体错误点

Job A的outputs字段写的是:

outputs:
  comment: ${{ steps.find-comment.outputs.comment }}

但peter-evans/find-comment@v2这个Action的输出字段是comment-id(找到评论时返回ID,未找到则为空),并不存在comment字段。同时你后续的Store find-comment output步骤虽然把comment-id存入了自己的输出,但Job A的outputs并没有引用这个步骤的输出,等于白做了这一步,最终Job A的comment输出始终是空字符串。

修正方案

方案一:简化流程,直接引用Action的输出

去掉多余的存储步骤,让Job A的outputs直接读取find-comment步骤的comment-id输出:

job-a:
    outputs:
      comment: ${{ steps.find-comment.outputs.comment-id }}
    steps:
    - name: Check if QR already exists
      uses: peter-evans/find-comment@v2
      id: find-comment
      with:
        issue-number: ${{ github.event.number }}
        comment-author: "github-actions[bot]"
        body-includes: Preview Bundle

    - name: Check find-comment outcome
      run: echo "This is the output of find-comment ${{ steps.find-comment.outputs.comment-id }}"

方案二:保留存储步骤,正确引用步骤输出

如果一定要保留中间存储步骤,需要给该步骤添加id,并让Job A的outputs引用这个步骤的输出:

job-a:
    outputs:
      comment: ${{ steps.store-comment.outputs.comment }}
    steps:
    - name: Check if QR already exists
      uses: peter-evans/find-comment@v2
      id: find-comment
      with:
        issue-number: ${{ github.event.number }}
        comment-author: "github-actions[bot]"
        body-includes: Preview Bundle

    - name: Store find-comment output
      id: store-comment
      run: echo "comment=${{ steps.find-comment.outputs.comment-id }}" >> $GITHUB_OUTPUT

    - name: Check find-comment outcome
      run: echo "This is the output of find-comment ${{ steps.find-comment.outputs.comment-id }}"

Job B的配置无需修改

修正Job A后,Job B的if条件always() && needs.job-a.outputs.comment == ''会正常工作:当PR上不存在指定评论时,comment为空,Job B运行;当存在评论时,comment为评论ID,Job B不会触发。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 01:31:03