Per environment variables in gitlab-ci yaml?

Problem to solve

As CI/CD Variables we can assign variables to individual environments. It is not clear how to achieve the same in .gitlab-ci.yaml

Steps to reproduce

As per the given gitlab-ci.yml, given a job that uses parallel matrix or similar means to deploy to multiple environments, one might need different variables to apply to each. It is, however, an error to use $ENV in an extends directive.

Configuration

.environments:
  parallel:
    matrix:
      - ENV: development
      - ENV: staging
      - ENV: production

.env:development:
  variables:
    URL: http://dev.example.com
.env:staging:
  variables:
    APP_URL: http://staging.example.com
.env:production:
  variables:
    APP_URL: http://example.com

deploy:
  extends:
  - .environments
  - .env:$ENV
  environment:
    name: $ENV

Hi,

Perhaps you could try combining everything rather than attempting to separate it all?

e.g.

deploy:
  script:
    - echo "$DEV:$APP_URL"
  parallel:
    matrix:
      - DEV:      "development"
        APP_URL:  "http://dev.example.com"
      - STAGING:  "staging"
        APP_URL:  "http://staging.example.com"
      - PROD:     "production"
        APP_URL:  "http://example.com"

You could still use variables and make the content of matrix bit dynamic.

Parallel matrix is a bad fit for many variables as all the matrix values get added to the job name so it quickly degenerates into a huge mess, especially as we have variable numbers of environment driven settings we want to change per environment.