Travis CI tests branches with an appropriate set of environment variables

I have a project that I am trying to automate tests using Travis CI. I have a dev branch and a test branch, and they have different environment variables. For example, in dev branches I need to connect to a different API than the testing branch indicated by the environment variable. So, when I run the assembly on the dev branch on Travis, how do I configure it to be tested only with a set of environment variables, and also for assembly on the test branch?

+7
travis-ci
source share
3 answers

There is no great way to do this right now, but you can write a shell script that checks the Travis environment variable TRAVIS_BRANCH (which returns the branch that Travis is testing) and sets the appropriate environment variables in response. Here is a brief example (note that I am not an expert in shell scripts, so if I screwed up this or did something stupid, let me know and I will fix it):

 if [ ${TRAVIS_BRANCH} == development ]; then TEST_MODE=dev stuff else TEST_MODE=master stuff fi export TEST_MODE 
+6
source share

Travis can have different .travis.yml configurations for each branch. Therefore, changing .travis.yml on the test branch does not affect .travis.yml on the 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} 
+4
source share

.travis.yml

 branches: only: - master - dev 

Readme

To correctly display the test result in any branch, you can configure the status image by changing the query string "? Branch ="

https://travis-ci.org/[USER.BIZ/[project] PNG? Branches = [DP]

Links: Travis Configuration

-4
source share

All Articles