1

I execute a main-action with an entrypoint.sh bash script that returns an environment variable named MATRIX_LIST that looks like this [value1,value2,value3] and then I transfer it to the next job (second_job) as output.

The problem is I want the strategy.matrix within the second_job to run as the number of ${{ needs.first_job.outputs.MATRIX_LIST }} but it does not work and return me this error

Error when evaluating 'strategy' for job 'second_job'. (Line: 44, Col: 19): Unexpected value '[value1,value2,value3]'

jobs:
  first_job:
    runs-on: ubuntu-latest
    name: Return the MATRIX_LIST environment variable
    outputs:
      MATRIX_LIST: ${{ env.MATRIX_LIST }}

    steps:
      - name: Checkout Local Repository
        uses: actions/checkout@v1

      - name: Main Action Step (Set MATRIX_LIST into GITHUB_ENV)
        uses: ./.github/actions/main-action
        with:
          first-key: ${{ secrets.KEY }}

  second_job:
    runs-on: ubuntu-latest
    name: Trigger the matrix job N times depending to the MATRIX_LIST output variable
    needs: [first_job]

    strategy:
      matrix:
        services: ${{ needs.first_job.outputs.MATRIX_LIST }}

    steps:
      - name: Print the value of service name ${{ matrix.service }}
        run: |
              echo "Hello: ${{ matrix.service }}"

Is it possible to set an outputs variable within GitHub's index/list expression syntax?

Updated (entrypoint.sh Bash Script):

function Convert_Array_To_Matrix_Index_List()
{
    services_array=(value1,value2,value3)

    for SERVICE in ${services_array[@]}; do
        second_array+=("${SERVICE}")
    done

    MATRIX_LIST=`(IFS=,; echo "[${second_array[*]}]")`
    echo "MATRIX_LIST=${MATRIX_LIST}" >> $GITHUB_ENV
}
4
  • Does this answer your question: stackoverflow.com/questions/59977364/…? Commented Jan 16, 2021 at 13:06
  • I don't think so, I'm not using or can generate a JSON format Commented Jan 16, 2021 at 13:31
  • Why can't you just transform it? Commented Jan 16, 2021 at 14:21
  • I've modified my question and add the entrypoint.sh bash script. :) It will be great if you could share with me the corrections I need to make to my code :))) Commented Jan 16, 2021 at 17:50

0

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.