我对YAML语法不太熟悉,在验证我的bitbucket-pipelines.yaml文件时遇到了一些麻烦。
我从在线YAML解析器中获得以下内容:
ERROR:
while scanning for the next token
found character '%' that cannot start any token
in "<unicode string>", line 18, column 234:
... CKET_BRANCH, \"Date\": $(date +"%m-%d-%y"), \
语法有什么问题?如何更正此错误?
pipelines:
branches:
master:
- step:
script:
- echo "Runing pip-lee-nes for ARGUS"
- echo "Deploy to live"
- export AWS_ACCESS_KEY_ID=$LIVE_AWS_ACCESS_KEY_ID
- export AWS_SECRET_ACCESS_KEY=$LIVE_AWS_SECRET_ACCESS_KEY
- export AWS_DEFAULT_REGION=$LIVE_AWS_REGION
- node -v
- npm --version
- npm run config $LIVE_BUCKET_NAME $LIVE_AWS_REGION
- npm run setup
- "aws sns publish --topic-arn arn:aws:sns:$LIVe_REGION:$LIVE_AWS_ACCOUNT_ID:new_release --subject \"$BITBUCKET_REPO_SLUG\" --message \"{\"Commit\": $BITBUCKET_COMMIT, \"Branch\": $BITBUCKET_BRANCH, \"Date\": $(date +"%m-%d-%y"), \"Time\": $(date +"%T")}\"
develop:
- step:
script:
- echo "Runing pip-lee-nes for ARGUS"
- echo "Deploy to staging"
- export AWS_ACCESS_KEY_ID=$STAGING_AWS_ACCESS_KEY_ID
- export AWS_SECRET_ACCESS_KEY=$STAGING_AWS_SECRET_ACCESS_KEY
- export AWS_DEFAULT_REGION=$DEFAULT_REGION
- node -v
- npm --version
- npm run config $STAGING_BUCKET_NAME $DEFAULT_REGION
- npm run setup
- "aws sns publish --topic-arn arn:aws:sns:$DEFAULT_REGION:$STAGING_AWS_ACCOUNT_ID:new_release --subject \"$BITBUCKET_REPO_SLUG\" --message \"{\"Commit\": $BITBUCKET_COMMIT, \"Branch\": $BITBUCKET_BRANCH, \"Date\": $(date +"%m-%d-%y"), \"Time\": "$(date +"%T")}\"
答案 0 :(得分:3)
如果你稍微缩短有问题的标量:
"aws ... \"Branch\": $BITBUCKET_BRANCH, \"Date\": $(date +"%m-%d-%y"), \"Time\": $(date +"%T")}\"
您可以看到它以双引号开头,以\
之后的第一个未转义(即无: $(date +
)双引号结束。解析器读取的下一个标记,以%
开头来自%m-%d-%y
并且不允许这样做。你可能想这样做:
"aws ... \"Branch\": $BITBUCKET_BRANCH, \"Date\": $(date +\"%m-%d-%y\"), \"Time\": $(date +\"%T\")}"
(请注意,我插入了4个反斜杠和删除了尾部双引号的反斜杠)。这样你就得到一个有效的双引号YAML标量。
由于你只是转义双引号并且你的字符串中没有单引号,你可能最好使用整个单引号并删除反斜杠:
- 'aws sns publish --topic-arn arn:aws:sns:$LIVe_REGION:$LIVE_AWS_ACCOUNT_ID:new_release --subject "$BITBUCKET_REPO_SLUG" --message "{"Commit": $BITBUCKET_COMMIT, "Branch": $BITBUCKET_BRANCH, "Date": $(date +"%m-%d-%y"), "Time": $(date +"%T")}'