Travis if语句不执行

时间:2018-01-11 07:56:03

标签: bash travis-ci

由于某种原因,当我使用if语句时,它不会执行配置。以下是我的完整travis.yml

travis.yml:

language: php
php:
    - '5.6.32'
    - '7.0.26'
    - '7.1.12'
    - '7.2.0'
os:
    - windows
    - linux
git:
    depth: 1
matrix:
    fast_finish: true
sudo: false
before_install:
    - if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.2.0" ]]; then git clone -b stable https://github.com/jedisct1/libsodium.git; fi
    - if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.2.0" ]]; then cd libsodium && sudo ./configure && sudo make check && sudo make install && cd ..; fi
install:
    - if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.2.0" ]]; then pecl install libsodium; fi
    - if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.2.0" ]]; then echo "extension=sodium.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
    - travis_retry composer install --no-interaction
    - wget -c -nc --retry-connrefused --tries=0 https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar
    - chmod +x coveralls.phar
    - php coveralls.phar --version
before_script:
    - mkdir -p build/logs
    - ls -al
script:
    - ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml
after_success:
    - travis_retry php coveralls.phar -v
branches:
    only: master
cache:
    directories:
        - vendor
        - $HOME/.cache/composer

因此出于某种原因

- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.2.0" ]]; then 
     export git clone -b stable https://github.com/jedisct1/libsodium.git;
 fi

无效,我从this

获得此解决方案

我的目标是在某些PHP版本上执行某些行。

我错过了什么吗?

1 个答案:

答案 0 :(得分:4)

修改

您提取了TRAVIS_PHP_VERSION的前3个字符,并将其与5个字符进行了比较..当然,这不起作用。你可以试试:

if [[ ${TRAVIS_PHP_VERSION:0:5} == "7.2.0" ]]

if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.2" ]]

结束编辑

我在Travis配置文件中运行脚本时遇到了一些问题,因为我想要空行和注释,Travis对此感到困惑。所以一般来说我会建议在单独的bash文件中编写脚本。

最简单的方法是在脚本文件中执行所有bash脚本并使用travis.yml中的脚本文件

before_install: ./travis-scripts/before_install.sh

现在您可以使用bash语法编写脚本,它们可以立即运行。

如果您仍想在travis文件中编写脚本,请尝试(不是每次都适用于我):

install: >
    if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.2" ]]; then pecl install libsodium; fi;
    if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.2" ]]; then echo "extension=sodium.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi;
    travis_retry composer install --no-interaction;
    wget -c -nc --retry-connrefused --tries=0 https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar;
    chmod +x coveralls.phar;
    php coveralls.phar --version;

或保持原样,只将if语句放在引号中。