hyprstack hyprstack - 8 days ago 5
YAML Question

Invalid YAML file

I'm not very familiar with YAML syntax, and am having some trouble with validating my bitbucket-pipelines.yaml file.

I get the following from an online YAML parser:

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"), \


What is wrong with the syntax? How do I correct this error?

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")}\"

Answer

If you shorten the offending scalar a bit:

"aws ... \"Branch\": $BITBUCKET_BRANCH, \"Date\": $(date +"%m-%d-%y"), \"Time\": $(date +"%T")}\"

You can see that it starts with a double quote and ends with the first unescaped (i.e. no \) double quote after : $(date + The next token the parser reads, starts with % from %m-%d-%y and that is not allowed. You probably wanted to do:

"aws ... \"Branch\": $BITBUCKET_BRANCH, \"Date\": $(date +\"%m-%d-%y\"), \"Time\": $(date +\"%T\")}"

(note that I inserted 4 backlashes and removed the backslash for the trailing double quotes). That way you get a double quoted YAML scalar that is valid.

Since you are only escaping the double quotes and have no single quotes in your string, you're probably better off by using single quotes around the whole and dropping the backslashes:

- '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")}'