Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perform after_success actions conditionally?

Tags:

travis-ci

I'm working on a project that deploys to a provider not currently supported by Travis, so I've written my deployment step in an after_success block. However, I'd like to configure Travis to only deploy on new tags. I know this is possible when using the deploy: block, by adding

deploy:
  # ...
  on:
    tags: true

to the deploy: block.

Is the same possible in after_success? If not, is there another way to only do certain actions in after_success if I'm on a new tag?

If Travis doesn't support this, I can just write a shell script to run after all successes, check if on a new tag, and then conditionally do the deployment, but I'd much prefer to be able to have Travis do it automatically.

Thanks!

like image 763
Eliza Weisman Avatar asked Mar 16 '15 17:03

Eliza Weisman


1 Answers

Yep! I need the exact same thing and worked around it by doing:

after_success:
  if ([ "$TRAVIS_BRANCH" == "master" ] || [ ! -z "$TRAVIS_TAG" ]) && 
      [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
    echo "This will deploy!"
  else
    echo "This will not deploy!"
  fi

I hope they introduce the on: tags: functionality for the after_success event, it'll make things easier and keep the build script cleaner.

like image 173
AdaptiveCoder Avatar answered Nov 20 '22 20:11

AdaptiveCoder