Travis CI - Set variable based on the value of another one (TCI Enterprise)

I’m on Travis Enterprise and I want to conditionally run some jobs depending on the kind of build, in particular, I want to include additional jobs when the event that triggers the CI is the push of a tag.

Looking at the documentation (here about env variables and here about conditions), I was able to do that by using a condition like:

if: tag IS present

and it works fine, but I would like to define a new environment variable like IS_BUILDING_A_TAGthat is true when building a tag and false otherwise so that I could rewrite the previous condition like:

if: env(IS_BUILDING_A_TAG)

I tried with:

env:
 - BUILDING_A_TAG=tag IS present

but I get the error invalid env var on Travis. Can’t find any docs on this. @Montana, any clue?

Hi @howtotalktogirls,

In Travis, it’s possible to create different jobs, each with its own set of environment variables. You’d do something like:

jobs:
  include:
    - if: branch = master
      env: 
      - RESOLVER="nightly"
      - STACKYAML="post.yml"
    - if: NOT (branch = master)
      env:
      - RESOLVER="lts-12.11"
      - STACKYAML="pre.yml"

One thing to be aware of is, historically in Travis, multiple jobs are simultaneously true, Travis will launch multiple simultaneous jobs, so if you don’t want a commit to kick off multiple jobs, be careful to make sure that the conditions you set are mutually exclusive, as they are in this case I presented above.

1 Like