2015-08-20 65 views
4

我有一個開源項目,我要部署的代碼只是如果代碼是在主分支,我已經嘗試了許多技術途徑,如:如何僅在travis-ci中的主分支中運行命令?

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

或者喜歡的東西:

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.") 

但這不起作用,即使在其他人的分支中,fab deploy命令也被觸發。

回答

5

我不知道爲什麼你的第一個方法是行不通的,但我會建議使用在你.travis.yml文件deploy:指令,像這樣的自定義部署腳本:

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

這裏是documentation

希望這會有所幫助。