How to create configuration files that contain colons in YAML?

continuous-integration, gitlab-ci, yaml

Solution

It should work if you wrap the whole line within quotes like this:

- 'echo "foo: $VAR" > site.yml'

Gitlab's CI lint marks it as correct syntax.

See here for more info.

Problem

According to CI's lint, this yml is not valid: ``` pages: stage: deploy image: python:3.5 script: - echo "foo: $VAR" > site.yml - cat ~/.python-gitlab.cfg artifacts: paths: - _build only: - master ``` error: ``` jobs:pages:script config should be a string or an array of strings ``` If I remove the colon on the `echo` line, it works. What I want to do is to create some configuration files on the fly, to comply to existing tools, using private variables, like `echo "url: $CI_PROJECT_URL" > site.yml` to produce ``` url: "https://gitlab.com/group/project" ``` But I can't do this because the yaml is said invalid, and I don't find workarounds. Or I must write code around my tools to pass command line arguments instead of reading config files. Still, this colon stuff seems a bug.

Original source