The Cookbook: Deployment

Header

In this cookbook, we are going to show you just how flexible you can make the Travis deployment options using bash scripts, stick around and we will show you a great example.

Deployment flexibility

Sometimes your deployment needs more customization than the after_success method allows, if this is the case use a custom bash script. For example, the bash script I wrote below is a script to ignore PR’s:

#!/usr/bin/env sh

echo "Hello from Montana at Travis"
echo $TRAVIS_PULL_REQUEST

if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then
  surge --project ./dist --domain auto-deploy-test.surge.sh
else
  echo "This is a PR, not deploying"
fi

In some cases, this will fail – you must remember to set permissions. For example, let’s say this script I just created above I named ignore.sh, I would need to add this in my script section:

chmod +x ./ignore.sh && ./ignore.sh

In this case, your .travis.yml file would look like this:

deploy:
  provider: script
  script: chmod +x ./ignore.sh && ./ignore.sh
  on:
    branch: dev

There you go and congratulations you’ve successfully added a bash script in your .travis.yml to instruct your deployment to ignore PR’s, this is just one of the many things you can do with bash when it comes to customizing your deployments.