-
I have a workflow building several docker images and only publishing those images if all builds succeed. The obvious way to solve this was to have a build job with a matrix of the image names and then a publish job with the same matrix that “needs” the build job. This works fine. However now I also want to generate outputs during build for each image that I want to re-use during the publish job for the same image. I know that I can work around this using artefacts but if these weren’t matrix jobs I could just do it using outputs. Is there a special syntax to do access outputs from a matrix job or are matrix jobs simply incapabl of generating outputs? I can’t find any explanation of this in the docs and it doesn’t seem like the outputs could be named dynamically since they need to be explicitly defined at the job level. |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 15 replies
-
Hey Alan, matrix jobs can set outputs but they will overwrite each other. The last one wins. As a workaround, you can add a unique parameter for each matrix job and use that to set outputs with different names: [BUG] Jobs output should return a list for a matrix job - #15 by Simran-B |
Beta Was this translation helpful? Give feedback.
-
Hey thanks Simran, looks like I’ll have to duplicate the matrix list for the outputs then. That solution seems obvious in hindsight but didn’t occur to me. |
Beta Was this translation helpful? Give feedback.
-
Simran-B:
This is not great. I hope the GitHub team will fix this. |
Beta Was this translation helpful? Give feedback.
-
Been trying some workarounds for days now, and no it is no possible. The only think I can think of is to set a secret to a repository and check the value afterward. So you can't use job level env, you can't set output dynamicaly, thoses values are overwritten by each matrix jobs... |
Beta Was this translation helpful? Give feedback.
-
One of the options is to pass outputs via output artifacts, using GH actions upload-artifact and download-artifact: name: "CI/CD"
on:
push:
branches: [master]
defaults:
run:
shell: bash
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
kv:
- key: one
val: ONE
- key: two
val: TWO
- key: three
val: THREE
steps:
- id: one
run: |
mkdir -p pipelines
echo ${{ matrix.kv.val }} >> outputs/${{ matrix.kv.key }}.txt
- uses: actions/upload-artifact@v3
with:
name: outputs
path: outputs/*.txt
getval:
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: actions/checkout@v3
- name: Load outputs
uses: actions/download-artifact@v3
with:
name: outputs
path: outputs
- run: |
ls outputs
cat outputs/*.txt |
Beta Was this translation helpful? Give feedback.
-
That works because name: Works
on:
push:
branches: ["**"]
jobs:
parallel:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
option:
- a
- b
steps:
- name: output
id: output
run: |
echo "${{ matrix.option }}=${{ matrix.option }}" >> $GITHUB_OUTPUT
outputs:
a: ${{ steps.output.outputs.a }}
b: ${{ steps.output.outputs.b }}
finally:
needs: parallel
runs-on: ubuntu-latest
strategy:
matrix:
option: ${{ needs.parallel.outputs.* }}
steps:
- name: checkout
uses: actions/checkout@v3
- name: debug
run: echo '${{ toJSON(needs.parallel.outputs) }}' |
Beta Was this translation helpful? Give feedback.
-
Facing this problem too. My workflow is dynamic matrix jobs so that's not possible to pre-define outputs statically |
Beta Was this translation helpful? Give feedback.
-
I have used this action to solve the problem, works well with dynamic matrix jobs: https://github.com/marketplace/actions/matrix-outputs-write |
Beta Was this translation helpful? Give feedback.
-
We've made a couple of actions to deal with this issue: |
Beta Was this translation helpful? Give feedback.
-
I've developed an action to workaround this problem. It only requires adding one additional step to your job matrix and setting and output: https://github.com/beacon-biosignals/matrix-output |
Beta Was this translation helpful? Give feedback.
Hey Alan, matrix jobs can set outputs but they will overwrite each other. The last one wins. As a workaround, you can add a unique parameter for each matrix job and use that to set outputs with different names: [BUG] Jobs output should return a list for a matrix job - #15 by Simran-B