0

I have configured my github actions which runs tests in parallel for different platforms. At the end of my tests I want the status to be saved to the outputs. Once all jobs complete I have another job that runs to send the results to a slack webhook.

I am having difficulty determining a method to save the output for multiple jobs and assuring there is no issues when they are running in parallel.

For example this is my code snippet

name: Test Notify

on:
  push:

jobs:
  build:
    strategy:
      matrix:
        config:
          - name: 'Ubuntu 18.04'
            runner: 'ubuntu-18.04'
            id: 'u18'

          - name: 'Ubuntu 20.04'
            runner: 'ubuntu-20.04'

      fail-fast: false

    runs-on: ${{ matrix.config.runner }}

    outputs:
      # Prefer to have one general output I can append to
      global: ${{ steps.status.outputs.global }}

      # I can output to separate outputs but I rather have a single one as shown above
      u18: ${{ steps.status.outputs.u18 }}
      u20: ${{ steps.status.outputs.u20 }}

    steps:

      - name: Test Failure u18
        id: step1
        if: ${{ matrix.config.id == 'u18' }}
        run: |
          exit 1

      - name: Doing Step 2
        id: step2
        run: |
          echo "DO NOTHING"

      - name: Output Status
        id: status
        if: always()
        env:
          JOB_STATUS: "${{ job.status }}"
        run: |
          # This works, but is it safe since I have u18 and u20 running in parallel ?
          echo "${{ matrix.config.id }}=$JOB_STATUS" >> $GITHUB_OUTPUT

          # Is there a safe way to have a single status string that I add to, for example;
          # echo "global=${{ github_output.global}}$JOB_STATUS" >> $GITHUB_OUTPUT


  webhook:
    needs: build
    runs-on: 'ubuntu-20.04'
    if: always()
    steps:
      - name: Send webhook update for all jobs
        env:
          JSON_RESULTS: "${{ toJSON(needs.build-and-test) }}"
        run: |
          # Will add code to properly send the information
          echo $JSON_RESULTS
Sacha
  • 9

1 Answers1

0

Currently, there is no easy way to reference all outputs of matrix jobs. Moreover combining it into a single output.

The issue is that only a single value is available for future jobs that need the strategy.matrix job’s output because even if the output is set by multiple matrix variations of the job, only one is retained.

For more detail, see the Community discussion.

TL;DR:

There are several workarounds:

  • defining separate outputs for a job with strategy.matrix by letting the job variations set different outputs

    • then process these outputs in a separate step that can provide single output for further steps
  • use artifacts to store the matrix jobs' outputs and then post-process it (discussioncomment-3814009)

Andrii Bodnar
  • 1,672
  • 2
  • 17
  • 24