2015-02-23 87 views
3

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配置腳本​​來做到這一點?

回答

6

您可以使用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 

後者也可能是你在找什麼,前者是少一點冗長。

+0

謝謝 - 它看起來像環境變量TRAVIS_PHP_VERSION實際上可用於'腳本'塊中調用的任何bash腳本。由於條件實際上有點複雜,我已將它移動到通過「./cflags.sh」調用的單獨腳本中 – Danack 2015-02-24 00:45:59