Bootstrap FreeKB - GitHub Actions - GitHub JSON output between jobs
GitHub Actions - GitHub JSON output between jobs

Updated:   |  GitHub Actions articles

GitHub Actions can be used to do something whenever something happens in one of your GitHub repositories. If you are not familiar with GitHub Actions, check out my article Getting Started with GitHub Actions.

This also assumes you are familiar with Output. If not, check out my article GitHub Actions - Getting Started with Output.

You can

Here is an example of how you can create JSON in job 1 and then use the JSON in job 2.

name: my workflow
run-name: ${{ github.workflow }} run by ${{ github.actor }}
on:
  workflow_dispatch:
jobs:
  job1:
    runs-on: ubuntu-latest
    outputs:
      food: ${{ steps.xfood.outputs.food }}
    steps:
      - name: define food as a JSON list
        id: xfood
        run: echo "food={'include':[{'fruit':'apple','veggy':'pepper'}]}" >> $GITHUB_OUTPUT 

  job2:
    runs-on: ubuntu-latest
    needs: job1
    strategy:
      fail-fast: false
      matrix: ${{ fromJSON(needs.job1.outputs.food) }}
    steps:
      # This should return: {fruit: apple, veggy: pepper}
      - name: full JSON
        run: echo "${{ toJSON(matrix) }}"

      # This should return apple
      - name: matrix.fruit
        run: echo "${{ toJSON(matrix.fruit) }}"  

      # This should return pepper
      - name: matrix.veggy
        run: echo "${{ toJSON(matrix.veggy) }}"    

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 70e40e in the box below so that we can be sure you are a human.