How to run a command only if this is the main branch in travis-ci?

I have an open source project, and I want to deploy the code only if the code is in the main branch, I have already tried many approaches, for example:

- if [[ $TRAVIS_BRANCH == 'master' ]]; then fab deploy; fi 

Or something like:

 BRANCH = "master" def _get_local_branch(): return local("git rev-parse --abbrev-ref HEAD", capture=True) def deploy(): local_branch = _get_local_branch() if local_branch == BRANCH: print green("Deploy succefully done!") print yellow("Deploy allowed just in the master branch.") 

But this does not work, even in other branches of people, the fab deploy command was called.

+4
source share
1 answer

I'm not sure why your first approach does not work, but I would suggest using the deploy: directive in your .travis.yml file with a custom deployment script as follows:

 deploy: provider: script script: scripts/deploy.sh on: branch: master 

Here is the documentation .

Hope this helps.

+5
source

All Articles