检测特拉维斯
问题描述:
PHP版本在我的特拉维斯文件我有几个PHP版本和脚本条目是这样的:检测特拉维斯
php:
- 5.6
- 5.5
- 5.4
- 5.3
script:
- export CFLAGS="-Wno-deprecated-declarations -Wdeclaration-after-statement -Werror"
- phpize #and lots of other stuff here.
- make
我想只有当PHP版本相匹配5.6运行export CFLAGS
线。
我理论上可以用一个讨厌的黑客来从命令行检测PHP版本,但我怎么能通过Travis配置脚本来做到这一点?
答
您可以使用Shell条件做到这一点:
php:
- 5.6
- 5.5
- 5.4
- 5.3
script:
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.6" ]]; then export CFLAGS="-Wno-deprecated-declarations -Wdeclaration-after-statement -Werror"; fi
- phpize #and lots of other stuff here.
- make
或者使用与explicit inclusions构建矩阵:
matrix:
include:
- php: 5.6
env: CFLAGS="-Wno-deprecated-declarations -Wdeclaration-after-statement -Werror"
- php: 5.5
env: CFLAGS=""
- php: 5.4
env: CFLAGS=""
- php: 5.3
env: CFLAGS=""
script:
- phpize #and lots of other stuff here.
- make
后者也可能是你在找什么,前者是少一点冗长。
谢谢 - 它看起来像环境变量TRAVIS_PHP_VERSION实际上可用于'脚本'块中调用的任何bash脚本。由于条件实际上有点复杂,我已将它移动到通过“./cflags.sh”调用的单独脚本中 – Danack 2015-02-24 00:45:59