Travis CI testing branches with corresponding set of environment variables

梦想的初衷 提交于 2019-12-05 02:34:23

There is no great way to do this right now, but you can write a shell script that checks the Travis environmental variable TRAVIS_BRANCH (Which returns the branch that Travis is testing) and sets respective environmental variables in response. Here is a short example (Please note that I'm not a expert in shell scripting so if I screwed this up or did something silly let me know and I'll fix it):

if [ ${TRAVIS_BRANCH} == development ]; then
    TEST_MODE=dev stuff
else
    TEST_MODE=master stuff
fi

export TEST_MODE

Travis can have different .travis.yml configs for each branch. So modifying .travis.yml on branch test doesn't affect .travis.yml on develop or master branch:

  • develop branch .travis.yml:

    env:
      - DEVELOP_BRANCH_VARIABLE=FOO
    script:
      - ./run-develop-branch ${DEVELOP_BRANCH_VARIABLE}
    
  • test branch .travis.yml:

    env:
      - TEST_BRANCH_VARIABLE=BOO
    script:
      - ./run-test-branch ${TEST_BRANCH_VARIABLE}
    
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!