[BUG] Jobs output should return a list for a matrix job

I am glad that the GH team implemented jobs.<jobs_id>.outputs but I found a scenario where this feature does not work as expected.

jobs:
  one:
    runs-on: ${{ matrix.os }}
    outputs:
      myvar: ${{ steps.step1.outputs.myvar }}    
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest]
    steps:
    - id: step1
      run: echo "::set-output name=myvar::${{ matrix.os }}"
  two:
    runs-on: ubuntu-latest
    needs: one
    steps:
    - run: echo '${{ needs.one.outputs.myvar }}'
    - run: echo '${{ toJson(needs.one.outputs.myvar) }}'
    - run: echo '${{ toJson(needs.one.outputs) }}'

The value of myvar is determined by the last job run, while it should be the accumulated value of all jobs in the matrix. In other words the output of a matrix job should be an array of values, not a string, one value for each execution. In the example [ubuntu-latest, windows-latest] or [windows-latest, ubuntu-latest].

3 Likes

In case you wonder why one would need this, I use a matrix job to build and push docker images and a dependent job to create the “multi-arch” manifest.

1 Like

Hi @giuliov,

Thank you for reaching this out!

It’s by designed. As doc mentioned below:

Job outputs are strings, and job outputs containing expressions are evaluated on the runner at the end of each job.

If you use matrix in first job, which will cause multiple checkruns for first job, the job output is determined by the last completed checkrun. The output value is overwritten by the last checkrun, it’s not accumulated.

I strongly disagree. First, documentation can be buggy just like code. Second, if the design is incomplete and current implementation surprise user, then design should improve and implementation as a consequence. I keep my stand that this is a bug and should be worked on at some point in time (or never).

Hi @giuliov,

Thanks for your reply! Based on the current appearance and doc description, the job output is working as expected, but i agree there could be some improvement for the design.

According to the policy, it’s recommended to raise a feedback ticket in below link where github product manager will take a review, they will help to check.

https://support.github.com/contact/feedback?contact[category]=actions

1 Like