Using CI_JOB_NAME as environment name

Problem to solve

Hello,

we’re trying to use ${CI_JOB_NAME%%_*} as environment name:

.production_deployment_parameters: &production_deployment_parameters
  <<: *default_deployment_parameters
  environment:
    name: ${CI_JOB_NAME%%_*}
    url:  https://${HOSTNAME_WORDPRESS}
  rules:
    - if: $CI_COMMIT_BRANCH == 'prod'
      when: manual

.staging_deployment_parameters: &staging_deployment_parameters
  <<: *default_deployment_parameters
  environment:
    name: ${CI_JOB_NAME%%_*}
    url:  https://${HOSTNAME_WORDPRESS}
  rules:
    - if: $CI_COMMIT_BRANCH == 'main'
      when: manual

but get the error message

If we try to use

.production_deployment_parameters: &production_deployment_parameters
  <<: *default_deployment_parameters
  variables:
    ENVIRONMENT: "${CI_JOB_NAME%%_*}"
  environment:
    name: ${ENVIRONMENT}
    url:  https://${HOSTNAME_WORDPRESS}
  rules:
    - if: $CI_COMMIT_BRANCH == 'prod'
      when: manual

.staging_deployment_parameters: &staging_deployment_parameters
  <<: *default_deployment_parameters
  variables:
    ENVIRONMENT: "${CI_JOB_NAME%%_*}"
  environment:
    name: ${ENVIRONMENT}
    url:  https://${HOSTNAME_WORDPRESS}
  rules:
    - if: $CI_COMMIT_BRANCH == 'main'
      when: manual

we get the error message

Steps to reproduce

We followed the links in the error messages, searched this forum, googled and read

Versions

Please select whether options apply, and add the version information.

  • Self-managed
  • GitLab.com SaaS
  • Self-hosted Runners

Versions

  • GitLab: Community Edition v16.11.2

Is this a parsing order problem?
Is there any way to use a substring of a job name as an environment name?

Thanx for any hint! :slight_smile: