How do I conditionally define environment variables?

This snippet fails:

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

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

@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.

Thank you.