我是 Github Actions 的新手,并尝试通过 github 操作在 AWS 多区域上部署代码。为此,我创建了一个具有此矩阵的脚本并将输出导出到工作流。
APP_DEPLOY_TO_DEV='
{
"environment": ["app_dev_eu-central-1", "app_dev_us-east-1" ],
"include":[
{
"aws_env": "app_dev_eu-central-1",
"aws_region": "eu-central-1",
},
{
"aws_env": "app_dev_us-east-1",
"aws_region": "us-east-1",
}
]
}'
MATRIX_PARAMS_COMBINATIONS=$APP_DEPLOY_TO_DEV
echo ::set-output name=matrix_combinations::$MATRIX_PARAMS_COMBINATIONS
我的工作流程代码:
- name: SetUp Matrix Combinations
id: matrix
run: |
chmod +x app_deploy.sh; ./app_deploy.sh
working-directory: .github/scripts
shell: bash
outputs:
matrix-combinations: ${{ steps.matrix.outputs.matrix-combinations }}
build-deploy:
runs-on: ubuntu-latest
timeout-minutes: 10
needs: [Setup-Matrix]
strategy:
matrix: ${{ fromJson(needs.Setup-Matrix.outputs.matrix-combinations) }}
steps:
- name: Print Combinations
run: |
echo "step output"
echo "${{ matrix.aws_env }}"; // here app_dev_us-east-1 is getting printed instead of array
echo "op ${{ toJson(needs.Setup-Matrix.outputs.matrix-combinations) }}" //I am getting proper json array here
我通过使用访问矩阵值${{ matrix.variable_names}}
。
但是当我看到我的工作时,正在创建 2 个工作,但配置相同(它需要 us-east 1)。不知道可能出了什么问题。以前我尝试使用策略矩阵GithubActions 策略矩阵我转移到 shell 脚本,因为我有多个 if 检查,这让我的工作流程看起来很笨拙。任何线索将不胜感激:)