I’m having troubles with using a deployment script that uses a multiline string. When the same script is run through a script stage, the commands work as expected.
Example config:
language: node_js
os:
- linux
- osx
script:
- |
echo building
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
echo "****> linux <****";
elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
echo "----> osx <----";
fi
deploy:
provider: script
on:
all_branches: true
script: |
echo deploying
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
echo "****> linux <****";
elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
echo "----> osx <----";
fi
Result:
deployingnif [[ linux == linux ]]
sh: 1: thenn: not found
sh: 1: nelif: not found
sh: 1: thenn: not found
sh: 1: nfi: not found
Even though the JSON view of the job config shows the script having the same \n newline characters inside the script definition, the deploy stage is not interpreting them correctly.
Your script value contains \n, which is turning into a single n on the way to the deployment provider. (It is not immediately clear to me where it’s happening.) So the script is:
which produces the output you are seeing. You can string all of this together into one line:
echo deploying; if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then echo "****> linux <****"; elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then echo "----> osx <----"; fi
Making the script fit on one line is one workaround, but a pretty messy one. It may look alright for this trivial case, but once it starts getting more complex with more (nested) conditional logic, that one line is very hard to maintain. Having the script moved into another file and using script: bash deploy.sh is another workaround that I found, but it makes more sense to me to have all of the logic in the .travis.yml file.