YAML_FILE_ERROR: did not find expected key

YAML_FILE_ERROR: did not find expected key

我尝试使用 aws codeBuild 运行 Buildspec 并尝试使用 jq 命令动态生成 process.json 文件。但是它在执行和构建失败时给出了一个错误..

build: 
              commands:
                - cp $CODEBUILD_SRC_DIR/qe/performance/* apache-jmeter-5.2/bin/
                - cd apache-jmeter-5.2/bin/
                - DATE=`date "+%Y%m%d-%H-%M-%S"`
                - aws s3 cp $DATE-Report s3://$JMeterScanResultBucket/${ProjectName}/$DATE --recursive
                - jq -n --arg appname "$appname" '{apps: [ {project: wsg, issuetype: "Test Execution", summary: "Test Execution for junit Execution"}]}' > process.json

但是,我收到以下错误:第 20 行转到上面的“jq”命令

DOWNLOAD_SOURCE 
Failed
YAML_FILE_ERROR: did not find expected key at line 20

YAML 中的冒号加 space(或换行符)表示它是映射中的 key-value 对:

key: value

您的 jq 命令包含几个冒号,后跟 spaces。

既然要单个字符串,就必须用引号引起来。

在 YAML 中有几种方法可以做到这一点。

这里单引号或双引号都不理想,因为字符串包含两种引号类型。

A folded block scalar 可能是这里最好的解决方案。换行符将折叠在一起作为 spaces.

- >
  jq -n --arg appname "$appname"
  '{apps: [ {project: wsg, issuetype: "Test Execution",
  summary: "Test Execution for junit Execution"}]}'
  > process.json

另一种方法是 literal block scalar,您必须像在 shell 脚本中那样转义换行符:

- |
  jq -n --arg appname "$appname" \
  '{apps: [ {project: wsg, issuetype: "Test Execution", \
  summary: "Test Execution for junit Execution"}]}' \
  > process.json