0

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?

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.