How do I conditionally define environment variables?

#1

This snippet fails:

matrix:
include:
- if: “${TRAVIS_OS_NAME}” = “linux”
env: TRAVIS_GOOS=darwin TRAVIS_CGO_ENABLED=0

#2

You can define it in your build script, no need for special syntax for that. E.g.:

before_install:
    - if [[ $TRAVIS_OS_NAME == "linux" ]]; then
          export TRAVIS_GOOS=darwin; export TRAVIS_CGO_ENABLED=0
      fi
1 Like
#3

@native-api’s suggestion works at runtime.

At configuration time, you could do it this way:

matrix:
  include:
    - os: linux
      env: TRAVIS_GOOS=darwin TRAVIS_CGO_ENABLED=0

This guarantees that this job will be running on Linux.

#4

Thank you.

closed #5