Github Actions工作流flow-target步骤因大数据卡住求助
解决Github Actions工作流因大base64数据卡在flow-target步骤的问题
你的问题核心是通过环境变量传递超大base64内容,导致curl命令行参数过大,shell处理缓慢甚至卡死。小数据时参数体积小能正常运行,大数据则触发性能瓶颈。以下是几种可行的解决方案:
方案1:用文件存储大内容,通过stdin传递给curl
避免将大值写入环境变量,改为写入文件,再用jq构造JSON并通过标准输入传给curl,彻底规避命令行参数过大的问题:
修改后的工作流步骤:
steps: - name: converting vqltobase64 run: | # 将处理后的内容写入文件,而非环境变量 base64 -w 0 metadata4.vql | cut -c 5- | iconv -f utf8 -t iso8859-5 > processed_content.txt - name: flow-target run: | # 用jq构造合法JSON,从文件读取内容,通过stdin传给curl jq -n --arg content "$(cat processed_content.txt)" \ '{"name":"test_rev-007","description":"revision_creation","content":$content}' \ | curl --location 'https://10.xxx.x.xx:xxxx/test/loadFromVQL' \ --header 'Content-type:application/json' \ --header 'Authorization:Basic xxxxxxxxxxx' \ --data @- > at.json - name: get target id run: echo "get_revision_id= $(jq '.id' at.json)" >> $GITHUB_ENV - name: print revision id run : echo "${{env.get_revision_id }}" - name: deploy to target env run: curl -g --location 'https://10.xxx.x.xx:xxxx/deployments' --header 'Authorization:Basic xxxxxxxxxxx' --header 'Content-Type:application/json' --data '{"revisionIds":[${{env.get_revision_id}}],"environmentId":82,"description":"test"}'
方案2:改用multipart/form-data上传文件(API支持时)
如果目标API支持接收multipart/form-data格式的请求,可以直接上传处理后的文件,这种方式比JSON内嵌大内容更高效:
steps: - name: converting vqltobase64 run: | base64 -w 0 metadata4.vql | cut -c 5- | iconv -f utf8 -t iso8859-5 > processed_content.txt - name: flow-target run: | # 用form字段传递参数,文件直接通过@符号上传 curl --location 'https://10.xxx.x.xx:xxxx/test/loadFromVQL' \ --header 'Authorization:Basic xxxxxxxxxxx' \ --form 'name="test_rev-007"' \ --form 'description="revision_creation"' \ --form 'content=@processed_content.txt' > at.json # 后续步骤保持不变
方案3:优化数据处理流程(可选)
- 检查
cut -c 5-是否为必要操作,如果可以移除,能直接减少数据体积; - 确认
iconv编码转换是否必须,若API端可直接处理UTF-8编码,可省略该步骤,避免不必要的数据转换开销。
内容的提问来源于stack exchange,提问作者User1515
相关产品推荐
相关产品推荐

