actions / actions/runner

Reusable workflow doesn't output the individual job `result`

Open
#2,495 7 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
6.3k
Forks
1.4k
Avg merge
1d 16h
Merged PRs (30d)
24

Description

Describe the bug
When using a reusable workflow and outputting the result of a job, the value resolves to an empty string.

To Reproduce
Create a caller workflow

name: Caller Workflow
on: [pull_request]

jobs:
  call:
    uses: ./.github/workflows/reusable.yml
  print_result:
    needs: call
    if: always()
    runs-on: ubuntu-latest
    steps:
      - name: Run
        run: |
            echo "${{ toJSON(needs.call.outputs.pass) }}"
            echo "${{ toJSON(needs.call.outputs.fail) }}"

Create a reusable workflow reusable.yml

name: Reusable
on:
  workflow_call:
    outputs:
      pass:
        value: ${{ jobs.pass.result }}
      fail:
        value: ${{ jobs.fail.result }}

jobs:
  fail:
    runs-on: ubuntu-latest
    steps:
      - run: exit 1
  pass:
    runs-on: ubuntu-latest
    steps:
      - run: exit 0

Expected behavior
The result to always be outputted from the reusable workflow.

Actual behaviour
The outputs (or results) resolve as empty strings.

Workaround
Oddly enough, it appears you can get the results to resolve when adding another mock output that uses a toJSON() expression, such as:

on:
  workflow_call:
    outputs:
      pass:
        value: ${{ jobs.pass.result }}
      fail:
        value: ${{ jobs.fail.result }}
      mock:
        value: ${{ toJSON(jobs.fail).result }}

Which results in the following being printed:

success
failure

Note that we are not even consuming that mock output.

Alternatively, you can wrap an output with toJSON and fromJSON and it will resolve:

    pass:
        value: ${{ fromJSON(toJSON(jobs.pass)).result }}

Feels like an async process isn't being awaited unless the outputs need to convert with an expression.

Runner Version and Platform

Version of your runner? GitHub Enterprise Cloud
OS of the machine running the runner? OSX/Windows/Linux/...ubuntu-latest

What's not working?

Without the toJSON output
image
With the toJSON output
image

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior with the caller workflow and reusable.yml examples, comparing direct jobs..result outputs with the toJSON/fromJSON variants. Confirm that pass and fail resolve to success and failure without a mock or conversion; the issue does not name a source file or test entry point.

Written by the indexing model from the issue text.

Assessment

Tech stack
github-actions
Domain
ci-cd
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.