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
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…