Bash logic structures and conditionals (if, case, loops, etc.) in Travis CI
Travis CI's documentation often mentions the fact that it can call out to shell scripts in your repository, and recommends anything more complicated than a command or two (maybe including a pipe or something) be placed in a separate shell script.
But there are times when it's a lot more convenient to just keep the Travis CI-specific logic inside my repositories' .travis.yml
file.
As it turns out, YAML is well-suited to, basically, inlining shell scripts. YAML's literal scalar indicator (a pipe, or |
) allows you to indicate a block of content where newlines should be preserved, though whitespace before and after the line will be trimmed.
So if you have a statement like:
if [ "${variable}" == "something" ]; then
do_something_here
fi
You can represent that in YAML via: