Skip to content

Cannot access jobs.<job_id>.result from on.workflow_call.outputs.<output_id>.value #3087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
benjaminmal opened this issue Jan 13, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@benjaminmal
Copy link

benjaminmal commented Jan 13, 2024

Describe the bug
I'm trying to set an output in my reusable workflow of the result of a job but can't access to jobs.<job_id>.result from on.workflow_call.outputs.<output_id>.value. I have a empty string. As stated in docs, I should be able to access it. I can correctly access my output from my caller workflow.

To Reproduce
Reusable workflow file:

on:
  workflow_call:
    outputs:
      result:
        value: ${{ jobs.build.result }}

jobs:
  build:
    if: 'true' == 'false' # Makes skip the job
    runs-on: ubuntu-latest
    steps:
      -  run: echo 'hello-world!'

Caller workflow file:

on:
  push: ~

jobs:
  build:
    uses: ./.github/workflows/build.yaml
    secrets: inherit

  deploy:
    needs: build
    uses: ./.github/workflows/deploy.yaml
    if: needs.build.outputs.result == 'skipped'
    secrets: inherit

Expected behavior
jobs.<job_id>.result must be skipped, I've got an empty string

Runner Version and Platform

Version of your runner? 2.311.0 GitHub Hosted

OS of the machine running the runner? ubuntu-latest

What's not working?

Doing (reusable workflow):

on:
  workflow_call:
    outputs:
      result:
        value: ${{ toJSON(jobs.build) }}

And (caller workflow):

on:
  push: ~

jobs:
  debug:
    needs: build
    steps:
      -  run: echo ${{ needs.build.outputs.result }}

Print:
Capture d’écran 2024-01-13 à 23 10 36

Workaround

I found an interesting workaround:

on:
  workflow_call:
    outputs:
      result:
        value: ${{ fromJSON(toJSON(jobs.build)).result }}

Works perfectly. I can access it in my caller workflow:

Capture d’écran 2024-01-13 à 23 15 09

@benjaminmal benjaminmal added the bug Something isn't working label Jan 13, 2024
@rosiejeays
Copy link

Hey!

I had a similar issue when I was trying to grab an output from a reusable workflow. My problem was that I was only defining the outputs in the job and not at the top level of the workflow. Your post helped me find what I was missing. You seem to maybe have the opposite happening - only the outputs defined at the top level and not in the job, however it's missing the 'outputs' call.
It looks like the GitHub output is also not being set in the run command.

Hopefully trying this will help you:

on:
  workflow_call:
    outputs:
      result:
        value: ${{ jobs.build.outputs.result }} # set this to call on the result value in the outputs in the build job

jobs:
  build:
    runs-on: ubuntu-latest
    outputs: 
      result: ${{ steps.hello-world.outputs.result}} # Define the output here with using the step id
    steps:
      - id: hello-world # provide an id to the step you are wanting to call on
        run: |
          result='hello world!' 
          echo "result=$result" >> $GITHUB_OUTPUT # Set the variable as GitHub output

@Funth0mas
Copy link

Please also note that your workaround observation is misleading: The ${{ fromJSON(toJSON(jobs.build)).result }} is actually ${{ jobs.build.result }}, it is a job outcome (and would likely work without the from/toJSON gymnastics). But you are comparing it with ${{ needs.build.outputs.result }} , note the empty outputs object also in your screenshot: "outputs": {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants
@Funth0mas @benjaminmal @rosiejeays and others