Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a open-source project and i want to deploy the code just if the code is in the master branch, i already tried many approachs, like:

- 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 not work, even in the other peoples branches, the fab deploy command was triggered.

like image 458
Luan Fonseca Avatar asked Aug 20 '15 22:08

Luan Fonseca


1 Answers

I'm not sure why your first approach doesn't work but I would suggest using the deploy: directive in your .travis.yml file with a custom deployment script like this:

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

Here is the documentation.

Hope this helps.

like image 55
Dominic Jodoin Avatar answered Sep 20 '22 00:09

Dominic Jodoin