Can't add ":' in echo command

Replace this template with your information

it is a simple stage, but spend me a lot of time to know the reason.

this code works

test:
  stage: verify
  script:
    - npm ci
    - npm run test
    - echo "CI_COMMIT_REF_NAME is ${CI_COMMIT_REF_NAME}"

this is not

test:
  stage: verify
  script:
    - npm ci
    - npm run test
    - - echo "CI_COMMIT_REF_NAME is: ${CI_COMMIT_REF_NAME}"

the only different is, I addd “:” in echo command, which should be fine. But seems Gitlab CI doesn’t like it. I got below error

Found errors in your .gitlab-ci.yml:
jobs:test:script config should be a string or a nested array of strings up to 10 levels deep
You can also test your .gitlab-ci.yml in CI Lint

Hi @ozbillwang

You have a duplicate - at the start of that line, which might be confusing YAML.

Hi @ozbillwang

this is unfortunate YAML limitation. If you need : in a YAML you need to quote the entire string.

job1:
  script:
    - echo "Error: YAML hates me" # this results in YAML syntax error
    - "echo \"Error: YAML loves me\"" # this is the correct YAML syntax
2 Likes

using double quote " and single quote ’ but NOT resolve variable:

- "echo 'Ref name: $CI_COMMIT_REF_NAME'"