通过cURL调用GitHub Actions触发报错:输入参数超出限制
GitHub Actions API调用参数超限问题解决办法
用cURL调用GitHub Actions的workflow dispatch接口时碰到了参数数量限制错误——提示最多允许10个input属性,但实际传了18个。但同样的参数在GitHub Actions UI里却能正常运行,下面是可行的解决思路:
错误信息
{ "message": "Invalid request.\n\nNo more than 10 properties are allowed; 18 were supplied.", "documentation_url": "https://docs.github.com/rest/reference/actions#create-a-workflow-dispatch-event" }
原调用命令
curl -L \ -X POST \ -H 'Content-Type: application/json' \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer xxxxxxxx" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/xxxx/xxxx/actions/workflows/main.yml/dispatches \ -d '{"ref":"topic-branch","inputs":{"account_id": "test-account-005", "app_id": "iu", "customer_id": "self", "customer_name": "xx", "billing_id": "xxxxx", "non_prod_environment_name": "Development", "non_prod_env_id": "dev", "PROJECT_KEY": "CUS", "parent_ou_id": "xxxx", "working_directory": "root", "create_1pass_vault": "false", "cloudcraft": "false", "enterprise_support": "false", "category": "internal", "builder": "xxxxxx", "skip_tekton": "true", "owner": "xxxx", "budget_daily": "20"}}'
解决办法
1. 合并相关参数为JSON字符串
把多个关联的参数打包成单个JSON格式的字符串,大幅减少input的属性数量。比如把账号信息、环境信息、开关类参数分别合并:
修改后的cURL请求体示例:
{ "ref": "topic-branch", "inputs": { "account_info": "{\"account_id\": \"test-account-005\", \"app_id\": \"iu\", \"customer_id\": \"self\", \"customer_name\": \"xx\", \"billing_id\": \"xxxxx\"}", "non_prod_env_info": "{\"environment_name\": \"Development\", \"env_id\": \"dev\"}", "PROJECT_KEY": "CUS", "parent_ou_id": "xxxx", "working_directory": "root", "feature_toggles": "{\"create_1pass_vault\": false, \"cloudcraft\": false, \"enterprise_support\": false, \"skip_tekton\": true}", "category": "internal", "builder": "xxxxxx", "owner": "xxxx", "budget_daily": "20" } }
在workflow里,用fromJSON函数解析这些合并后的参数:
- name: 解析账号信息 run: | echo "账号ID: ${{ fromJSON(inputs.account_info).account_id }}" echo "应用ID: ${{ fromJSON(inputs.account_info).app_id }}"
2. 将固定参数转为仓库变量/秘密
把不经常变动的参数(比如category、builder、owner)设置成仓库的环境变量或机密,不需要每次调用API都传递。在workflow里直接引用即可:
- name: 使用仓库变量 run: | echo "分类: ${{ vars.CATEGORY }}" echo "构建器: ${{ secrets.BUILDER }}"
3. 拆分Workflow为多个子流程
把原Workflow拆分成多个独立的子Workflow,通过workflow_call调用。每个子Workflow只处理部分参数,主Workflow的input参数就能控制在10个以内。
比如主Workflow只传递核心参数,然后调用子Workflow处理账号创建、环境配置等逻辑:
jobs: trigger-sub-workflows: runs-on: ubuntu-latest steps: - name: 调用账号创建子流程 uses: ./.github/workflows/create-account.yml with: account_info: ${{ inputs.account_info }} budget_daily: ${{ inputs.budget_daily }} - name: 调用环境配置子流程 uses: ./.github/workflows/configure-env.yml with: env_info: ${{ inputs.non_prod_env_info }} feature_toggles: ${{ inputs.feature_toggles }}
内容的提问来源于stack exchange,提问作者Ranopriyo Neogy
相关产品推荐
相关产品推荐

