Use output from a step in a previous job

I currently have a single job containing a bunch of steps, which conceptually can be divided in three parts: A, B and C. A collects some data, and B and C use this data. Since B and C don’t actually depend on each other, I tried to split them to run them in parallel:

Before:

jobs:
  A:
    steps:
      - id: get_data
        uses: ./action-A
      - uses: ./action-B
        with:
          data: ${{ steps.get_data.outputs.data }}
- uses: ./action-C
with:
data: ${{ steps.get_data.outputs.data }}

After:

jobs:
  A:
    steps:
      - id: get_data
        uses: ./action-A

  B:
needs: A
    steps:
      - uses: ./action-B
        with:
          data: ${{ ?? }}

  C:
needs: A
    steps:
      - uses: ./action-C
        with:
          data: ${{ ?? }}

What can I use instead of ?? to get the output generated by the step in the first job?

8 Likes

Any idea on how to solve this? In my case, job B and C need to run on different platforms (ubuntu, windows and macOS), so I cannot leave them all in the job A…

Hey @botellaa!

I’m a product manager on the GitHub Actions team. Sorry for the delay in responding! Since you would like to use B and C in parallel and on different platforms. I think what you’d like to do is use

https://github.com/marketplace/actions/upload-artifact

https://github.com/marketplace/actions/download-artifact

These allow you to save data from a job, which you can manually access yourself, or pull down as part of another job. Give it try and let us know!

1 Like

There should be a better way to do this. I can’t use artifacts because the output I’m trying to use is a secret value that was decrypted in Job A and needed in Job B.

7 Likes

:+1: Trying to do something similar right now. Running in to the same issue :confused:

Would also be glad for something like this…

I’m not sure if this was possible when this thread was created, but you can currently use jobs.<job_id>.outputs. Basically define the outputs of steps in one job as outputs of the job and then use them in other jobs via the needs context. The documentation link has an example.

3 Likes

I tried it using ::set-output name=output-name::${{steps.<step_id>.outputs.name}} but it doesn’t seem to work unfortunately.

UPDATE:

I forgot to set outputs at job level. This way does work.

2 Likes