env(FOO) in condition not working?

Take a look to this build, relevant part:

env:
  global:
    - OFFICIAL_REPO_SLUG="DanySK/conrec"
jobs:
  include:
    - stage: deploy
      if:  type != pull_request AND repo = env(OFFICIAL_REPO_SLUG)

As you can see, the deploy job does not get scheduled.

Now look at this build of the same project, relevant part:

env:
  global:
    - OFFICIAL_REPO_SLUG="DanySK/conrec"
jobs:
  include:
    - stage: deploy
      if:  type != pull_request AND repo = DanySK/conrec

as you can see, the deploy job now gets correctly scheduled, but I would have expected the two specs to be identical. Any hint on what is going on here?

Hi @DanySK, did you ever get this working?

I just added stages to canonical/multipass and noticed errors in evaluating the expression:

Unable to evaluate condition (no implicit conversion of nil into String)

It was working before, when the condition was global, and indeed the docs say:

Also, environment variables from your build configuration ( .travis.yml ) and repository settings are available, and can be matched using env(FOO) , see below.

Nope, I worked it around that time, since I got no answer, then lived with it. Sorry.

Was OFFICIAL_REPO_SLUG defined in the repository settings at the time when you were having problems, perhaps?

It was defined like this:

env:
  global:
    - GRAVIS="https://raw.githubusercontent.com/DanySK/Gravis-CI/master/"
    - TERM=dumb
    - OFFICIAL_REPO_SLUG="DanySK/conrec"

So, you didn’t touch https://travis-ci.org/DanySK/conrec/settings? It didn’t have OFFICIAL_REPO_SLUG there? My reproduction was https://travis-ci.org/github/BanzaiMan/travis_production_test/builds/661122698 (compare with https://travis-ci.org/github/BanzaiMan/travis_production_test/builds/661109314, a build with the identical configuration, but had a different FOO value). We will be fixing this soon, by allowing the build-specific values in .travis.yml to override the repo-wide settings in the Settings panel. (This is the way the build script behaves, and we believe it is the right behavior.)

@DanySK i believe that has been fixed a while ago (the original post is from Dec 19, sorry this has slipped through for so long). For example, this config https://travis-ci.org/github/svenfuchs/test/builds/661108524/config has produced two jobs https://travis-ci.org/github/svenfuchs/test/builds/661108524 as expected.

@Saviq this was a separate issue, as your condition is defined on a stage, not a job, and global env vars were indeed not available in that context. sorry about that. i have just shipped what i believe should fix your configuration. For example, this config https://travis-ci.org/github/svenfuchs/test/builds/661209321/config matches a pattern defined on a global env var against the branch on a condition on stage, like your config does, and it produces two jobs: https://travis-ci.org/github/svenfuchs/test/builds/661209321

2 Likes

Thanks @svenfuchs, I’ll report back if I have troubles again.

Good to know, thanks