Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create configuration files that contain colons in YAML?

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.

like image 788
Ehvince Avatar asked May 03 '17 14:05

Ehvince


2 Answers

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.

like image 105
Jawad Avatar answered Sep 17 '22 14:09

Jawad


Single quotes around the whole line, as depicted by @Jawad, works:

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

But if your command contains other single quotes, I find it easiest to use the pipe Block Scaler Style: |

- |
  echo "I want to echo the key"
  echo 'foo: $VAR' > site.yml

More documentation on Block Scaler Styles can be found here: http://www.yaml.org/spec/1.2/spec.html#id2760844

like image 28
Daniel Rich Avatar answered Sep 19 '22 14:09

Daniel Rich