CI rule - combine only/changes with variables

I need a build job to run if there was a change in certain directories OR if a variable is set to true.

The following does not work

      - some/dir/**/*
      - another/dir/**/*
      - $NIGHTLY_JOB == "true"

The above will run the job when NIGHTLY_JOB variable is true. The job does not run when there is code change in specified directories.

How to OR these two conditions in GitLab rules?

you need to get rid off the obsolete only and use rules instead:

  - if: $NIGHTLY_JOB == "true"
  - changes:
      - some/dir/**/*
      - another/dir/**/*

Sorry, forgot to mention, I cannot use ‘rules:’ because elsewhere in our massive build script we use ‘except’

When I used ‘rules’, I got an error stating it cannot go with ‘except’

What you want cannot be achieved by only or except. If you want more advanced logic in selecting when a job runs, you need to move to rules which is replacing only and except.

Understood. Thanks for the solution.