Travis CI 测试分支与相应的环境变量集 [英] Travis CI testing branches with corresponding set of environment variables

查看:26
本文介绍了Travis CI 测试分支与相应的环境变量集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,我正在尝试使用 Travis CI 自动化测试.我有一个 dev 分支和一个 test 分支,它们有不同的环境变量.例如,在 dev 分支上,我需要连接到与 test 分支不同的 API,由环境变量指定.因此,当我在 Travis 上的 dev 分支上运行构建时,如何设置它以使其仅使用 dev 环境变量集进行测试,并且同样在测试分支上进行构建?

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?

推荐答案

目前没有很好的方法可以做到这一点,但是您可以编写一个 shell 脚本来检查 Travis 环境变量 TRAVIS_BRANCH (它返回 Travis 正在测试的分支)并设置相应的环境变量作为响应.这是一个简短的例子(请注意,我不是 shell 脚本方面的专家,所以如果我搞砸了或者做了一些愚蠢的事情,请告诉我,我会修复它):

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 CI 测试分支与相应的环境变量集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆