> For the complete documentation index, see [llms.txt](https://ploegert.gitbook.io/til/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ploegert.gitbook.io/til/tools/github-actions/capture-an-output-value-for-use-in-a-later-step.md).

# Capture An Output Value For Use In A Later Step

GitHub Actions has a workflow command called `set-output`. This can be used to capture the output from a shell command in step. That output value can then be used in a later step.

A useful example of this is reading the version of a tool from a dot-file to tell a later step what version of that tool to install.

Here's the `.tool-versions` file included in my repository:

```
postgres 13.1
ruby 3.0.0
nodejs 15.4.0
```

Assuming I've already [checked out my repo](https://github.com/actions/checkout), I can find and read the `nodejs` version from my `.tool-versions` file with a step that uses `set-output`.

```yaml
  - name: Read Node.js version to install from `.tool-versions`
    id: nodejs
    run: >-
      echo "::set-output name=NODE_VERSION::$(
        cat .tool-versions |
        grep nodejs |
        sed 's/nodejs \(.*\)$/\1/'
      )"
```

`echo` runs the command in the string which sets `NODE_VERSION` as an output value to what ends up being `15.4.0`.

This output value can be referenced in a later step.

```yaml
  - name: Install required Node.js version
    uses: actions/setup-node@v1
    with:
      node-version: "${{ steps.nodejs.outputs.NODE_VERSION }}"
```

`steps` has a reference to the `nodejs` step (note the `id` above) which then has `outputs` like the `NODE_VERSION`.

[source](https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#using-workflow-commands-to-access-toolkit-functions)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ploegert.gitbook.io/til/tools/github-actions/capture-an-output-value-for-use-in-a-later-step.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
