我试图从JSON文件中迭代对象数组,但我无法。我现在得到这个错误:
为job 'create'评估'strategy'时出错。.github/workflows/rollingdeploymentyml (Line: 66, Col: 15):不期望序列
这是当前的工作流文件:
name: Rolling Deploy
on:
push:
branches: [ "main" ]
jobs:
servers:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.read-json.outputs.matrix }}
environment: Staging
steps:
... a few other steps in here to create the json file
- name: Read JSON
id: read-json
run: |
JSON=$(cat ./neededServers.json)
echo "matrix=${JSON//'%'/'%25'}" >> $GITHUB_OUTPUT
create:
needs: servers
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.servers.outputs.matrix) }}
steps:
- name: Test
run: echo "${{matrix.reference}}"
我在没有策略的create
中运行echo ${{needs.servers.outputs.matrix}}
,并且它打印JSON文件。这里也有一个示例JSON文件:
[
{
"config":"small",
"ID":"1234",
"memory":"4096",
"vcpus":"2"
},{
"config":"small",
"ID":"2345",
"memory":"4096",
"vcpus":"2"
}
]
我不确定是我做错了什么,还是这是不可能的。
JSON应该包含数组的"include"
键:
{
"include": [
{
"config":"small",
"ID":"1234",
"memory":"4096",
"vcpus":"2"
},
{
"config":"small",
"ID":"1234",
"memory":"4096",
"vcpus":"2"
}
]
}