Travis CI:如何通过自定义环境变量允许失败?

时间:2015-06-02 20:46:06

标签: travis-ci

关注this answer,我写了这个Travis配置文件:

language: php

php:
    - 5.3
    - 5.4
    - 5.5
    - 5.6
    - 7
    - hhvm
    - nightly

branches:
    only:
        - master
        - /^\d+\.\d+\.\d+$/

matrix:
    fast_finish: true
    include:
        - php: 5.3
          env: deps="low"
        - php: 5.5
          env: SYMFONY_VERSION=2.3.*
        - php: 5.5
          env: SYMFONY_VERSION=2.4.*
        - php: 5.5
          env: SYMFONY_VERSION=2.5.*
        - php: 5.5
          env: SYMFONY_VERSION=2.6.*
        - php: 5.5
          env: SYMFONY_VERSION=2.7.*
        - php: 5.5
          env: SYMFONY_VERSION=2.8.*@dev TEST_GROUP=canFail
    allow_failures:
        - php: nightly
        - env: TEST_GROUP=canFail

before_script:
    - composer self-update
    - if [ "$SYMFONY_VERSION" != "" ]; then composer require --dev --no-update symfony/symfony=$SYMFONY_VERSION; fi
    - if [ "$deps" = "low" ]; then composer update --prefer-lowest; fi
    - if [ "$deps" != "low" ]; then composer update --prefer-source; fi

script: phpunit

但Travis CI只将php nightly版本视为“允许失败”版本。我是否以错误的方式使用环境变量?

更新

只是精确,我知道我可以直接写出这样的环境:

matrix:
    include:
        - php: 5.5
          env: SYMFONY_VERSION=2.8.*@dev
    allow_failures:
        - env: SYMFONY_VERSION=2.8.*@dev

但我仍然不明白为什么其他方式不起作用。

2 个答案:

答案 0 :(得分:8)

您在allow_failures:中指定的是您允许的失败

"You can define rows that are allowed to fail in the build matrix. Allowed failures are items in your build matrix that are allowed to fail without causing the entire build to fail. This lets you add in experimental and preparatory builds to test against versions or configurations that you are not ready to officially support."

不幸的是,我相信矩阵读取你的第一组代码的方式与php nightly版本一样,作为“允许失败”的版本,环境是夜间的一部分。

由于Travis如何允许失败,它必须完全匹配,您不能只指定env:作为允许的失败,您必须为每个php版本指定您想要允许的env:例如失败

allow_failures:
  - php: 5.3
    env: SYMFONY_VERSION=2.8.*@dev TEST_GROUP=canFail
  - php: 5.4
    env: SYMFONY_VERSION=2.8.*@dev TEST_GROUP=canFail
  - php: 5.5
    env: SYMFONY_VERSION=2.8.*@dev TEST_GROUP=canFail
  - php: 5.6
    env: SYMFONY_VERSION=2.8.*@dev TEST_GROUP=canFail
  - php: 7.0
    env: SYMFONY_VERSION=2.8.*@dev TEST_GROUP=canFail
  - php: hhvm
    env: SYMFONY_VERSION=2.8.*@dev TEST_GROUP=canFail
  - php: nightly # Allow all tests to fail for nightly

答案 1 :(得分:1)

根据this issuephpenv键必须完美匹配。 env可以是单个值或数组,但在两种情况下都必须是完美匹配。所以如果你想要你的构建:

- php: 5.5
  env: SYMFONY_VERSION=2.8.*@dev TEST_GROUP=canFail

允许失败,你必须提供整个envSYMFONY_VERSION=2.8.*@dev TEST_GROUP=canFail以及整个env键和PHP版本(如果你有不同PHP版本的相同env键)。