1
0
mirror of synced 2026-01-07 18:01:41 -05:00

Provide example of using an output to define two matrixes (#33502)

This commit is contained in:
Josh Soref
2024-06-14 12:40:00 -04:00
committed by GitHub
parent f3f17a539f
commit f85d8f247c
2 changed files with 71 additions and 0 deletions

View File

@@ -48,6 +48,10 @@ redirect_from:
{% data reusables.actions.jobs.matrix-exclude %}
## Example: Using an output to define two matrices
{% data reusables.actions.jobs.matrix-used-twice %}
## Handling failures
{% data reusables.actions.jobs.section-using-a-build-matrix-for-your-jobs-failfast %}

View File

@@ -0,0 +1,67 @@
You can use the output from one job to define matrices for multiple jobs.
For example, the following workflow demonstrates how to define a matrix of values in one job, use that matrix in a second jobs to produce artifacts, and then consume those artifacts in a third job. Each artifact is associated with a value from the matrix.
```yaml copy
name: shared matrix
on:
push:
workflow_dispatch:
jobs:
define-matrix:
runs-on: ubuntu-latest
outputs:
colors: ${{ steps.colors.outputs.colors }}
steps:
- name: Define Colors
id: colors
run: |
echo 'colors=["red", "green", "blue"]' >> "$GITHUB_OUTPUT"
produce-artifacts:
runs-on: ubuntu-latest
needs: define-matrix
strategy:
matrix:
{% raw %}
color: ${{ fromJSON(needs.define-matrix.outputs.colors) }}
{% endraw %}
steps:
- name: Define Color
env:
color: ${{ matrix.color }}
run: |
echo "$color" > color
- name: Produce Artifact
uses: {% data reusables.actions.action-upload-artifact %}
{% raw %}
with:
name: ${{ matrix.color }}
path: color
consume-artifacts:
runs-on: ubuntu-latest
needs:
- define-matrix
- produce-artifacts
strategy:
matrix:
color: ${{ fromJSON(needs.define-matrix.outputs.colors) }}
steps:
- name: Retrieve Artifact
{% endraw %}
uses: {% data reusables.actions.action-download-artifact %}
{% raw %}
with:
name: ${{ matrix.color }}
- name: Report Color
run: |
cat color
{% endraw %}
```