ivan.ukr
ivan.ukr

Reputation: 3551

Multi-element output from step in Github Actions

I want to create a step in the job which will output multiple file names which then could be iterated in another step. Here is my test workflow:

name: test-workflow

on:
  push:
    branches: [ master ]

jobs:
  test-job:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout this repo
        uses: actions/checkout@v2
        with:
          fetch-depth: 2

      - name: Test1
        id: test1
        run: |
          for f in $(ls $GITHUB_WORKSPACE/.github/workflows); do
            echo "file: $f"
            echo "::set-output name=f::$f"
          done

      - name: Test2
        run: |
          for file in "${{ steps.test1.outputs.f }}"; do
            echo "$file detected"
          done

However, given $GITHUB_WORKSPACE/.github/workflows really contains multiple files (all committed to repo), step Test2 prints out only last file name listed in the step Test1 by ls. How can I set output f from the step Test1 to multiple values?

Upvotes: 0

Views: 1787

Answers (1)

Krzysztof Madej
Krzysztof Madej

Reputation: 40603

In your case you ovrwrite output. Please try to pass an array as output:

name: test-workflow

on:
  push:
    branches: [ master ]
  workflow_dispatch:

jobs:
  test-job:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout this repo
        uses: actions/checkout@v2
        with:
          fetch-depth: 2

      - name: Test1
        id: test1
        run: |
          h=""
          for g in $(ls $GITHUB_WORKSPACE/.github/workflows); do
            echo "file: $g"
            h="${h} $g"
          done

          echo "::set-output name=h::$h"

      - name: Test2
        run: |
          for file in ${{ steps.test1.outputs.h }}; do
            echo "$file.. detected"
          done

Upvotes: 1

Related Questions