Make job deploy to any environment and handle variables accordingly

Problem to solve

I want to run pipelines for numerous environments which I have created before over the GitLab WebGui. According to the selected environment I want to use variables specific for the current environment.

prepare environment:
  stage: deploy
    - mkdir -p "url/$CI_ENVIRONMENT_NAME"
    - some task with ENV.USER
    - some task with ENV.PASSWORD

Let’s say I set up the environments prod and dev. For each I set up variables/secrets USER and PASSWORD. My prepare environment job should create a directory according to the selected environment url/dev or url/prod. After that it should use the secrets specified for this environment to perform some tasks.

Unfortunately I cannot specify an environment when creating a GitLab pipeline neither can I run jobs via Operate/Environments that do not have a specific environment defined for them (as of CI/CD YAML syntax reference | GitLab)

With GitHub Workflows I can select an environment upon workflow creation. Can I somehow reproduce this behaviour with GitLab?

In GitHub it would look roughly like this

        type: choice
        required: true
        description: Environment
          - dev
          - prod

      - name: mkdir
        run: - mkdir -p "url/${{ github.event.inputs.environment }}"

Might be that I do not really understand the concept of GitLab environments, so any push into the right direction is appreciated.