GitLab Job中使用curl命令出现无效YAML配置错误求助
解决script配置错误:
script config should be a string or a nested array of strings up to 10 levels deep 问题场景
调用接口时触发错误提示:
:script config should be a string or a nested array of strings up to 10 levels deep
使用的YAML配置如下:
script: - curl -X GET --header 'Accept: application/json' 'https://main-demo-services.nr.dflop-swf-prod.bee.ds.local/services/dataUser/namebreak/recache/status/'
修复方案
这个错误是因为YAML解析器无法正确识别命令字符串中的特殊字符或格式,提供两种可行的修复方式:
方式1:转义引号并包裹整个命令
将curl命令用双引号包裹,同时转义命令内部的双引号,确保YAML能正确解析为单一字符串:
script: - "curl -X GET --header \"Accept: application/json\" \"https://main-demo-services.nr.dflop-swf-prod.bee.ds.local/services/dataUser/namebreak/recache/status/\""
方式2:使用YAML块字符串语法
用|标记定义块字符串,保留命令的原始格式,避免解析冲突:
script: - | curl -X GET --header 'Accept: application/json' 'https://main-demo-services.nr.dflop-swf-prod.bee.ds.local/services/dataUser/namebreak/recache/status/'
额外检查
确保YAML文件的缩进统一(用2或4个空格,不要混用制表符),缩进错误也可能导致解析失败。
内容的提问来源于stack exchange,提问作者e_wards
相关产品推荐
相关产品推荐

