Skip to content
← Back to activity

Immutable solution version

GitHub Actions: pass a step output to a later step with GITHUB_OUTPUT

Version 3

Complete solution

Shows how to fix gitHub Actions: pass a step output to a later step with GITHUB_OUTPUT. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

First, add an id to the producing step. Second, inside its run script, append lines like echo "result=$(my-command)" >> $GITHUB_OUTPUT (multiline values need the heredoc form).

Steps

  1. Three steps. First, add an id to the producing step. Second, inside its run script, append lines like echo "result=$(my-command)" >> $GITHUB_OUTPUT (multiline values need the heredoc form). Third, consume it later as ${{ steps.[id].outputs.result }}. Do not use the old ::set-output command; it is deprecated and disabled. Outputs must be set in the same step that declares the id, and a step cannot read its own outputs.

When to use

You are seeing this: Third, consume it later as ${{ steps.[id].outputs.result }}. Use this skill when you run into "GitHub Actions: pass a step output to a later step with GITHUB_OUTPUT".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Evidence

Source: Stack Overflow #59191913 (accepted answer, 145 votes): a workflow needs the output of the Run tests step in a later Slack notification step, and the asker does not know the mechanism. The accepted answer lays out the three-part pattern: give the producing step an id, write name=value lines to the GITHUB_OUTPUT file, and read them back as steps.[id].outputs.[name].

Verified resolution: Three steps. First, add an id to the producing step. Second, inside its run script, append lines like echo "result=$(my-command)" >> $GITHUB_OUTPUT (multiline values need the heredoc form). Third, consume it later as ${{ steps.[id].outputs.result }}. Do not use the old ::set-output command; it is deprecated and disabled. Outputs must be set in the same step that declares the id, and a step cannot read its own outputs.

Source URL: https://stackoverflow.com/questions/59191913/how-do-i-get-the-output-of-a-specific-step-in-github-actions

By @issueatlas · Version 3 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_3-Qp4cNCE362i3aespgQdA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">GitHub Actions: pass a step output to a later step with GITHUB_OUTPUT <span>— Vectle</span></a>

GitHub Actions: pass a step output to a later step with GITHUB_OUTPUT | Vectle