hgiesel hgiesel - 4 months ago 22
YAML Question

How to have newlines in travis.yml

I have a repository that uses

Travis CI
, and in the
.travis.yml
there I have this line:

script:
- vim -Nu <(cat <<-EOF
set nocompatible |
filetype off
EOF
) -c 'Script' > /dev/null


Sadly this doesn't work, as this is transformed into a single line and is executed like this:

vim -Nu <(cat <<-EOF set no compatible | filetype off | EOF ) -c 'Script' > /dev/null


This makes the
EOF
tag not working, as
EOF
needs to be in a single line.
An alternative would be to just use normal quotes like this:

script:
- vim -Nu <(cat 'set nocompatible |
filetype off
) -c 'Script' > /dev/null


Which works, and is fine, but I feel there must be a way to insert newlines into a
.travis.yml
. I have an alternative now, but I may not in the future. So how do you do it?

Answer

In YAML you can specify newlines in a scalar by using "" quoting and escaping the newlines (\n), or, and that is more natural for your case, by using a literal style block scalar:

script:
- |
  vim -Nu <(cat <<-EOF
  set nocompatible |
  filetype off
  EOF
  ) -c 'Script' > /dev/null
Comments