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
}
James
  • 875
  • 2
  • 15
  • 24
  • Does this answer your question: https://stackoverflow.com/questions/59977364/github-actions-how-use-strategy-matrix-with-script? – riQQ Jan 16 '21 at 13:06
  • I don't think so, I'm not using or can generate a JSON format – James Jan 16 '21 at 13:31
  • Why can't you just transform it? – riQQ Jan 16 '21 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 :))) – James Jan 16 '21 at 17:50

0 Answers0