Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Travis CI testing branches with corresponding set of environment variables

Tags:

travis-ci

I have a project that I'm trying to automate tests using Travis CI. I have a dev branch and a test branch, and they have different environment variables. For example, on the dev branch, I need to connect to a different API than the test branch, specified by an environment variable. So, when I run the build on the dev branch on Travis, how do I set it up so that it only tests with the dev set of environment variables, and likewise for build on test branch?

like image 686
Jack Avatar asked Jan 13 '14 19:01

Jack


1 Answers

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
like image 58
joshua-anderson Avatar answered Oct 15 '22 03:10

joshua-anderson