Use gitlab-ci to change environment, stage, branch in .deployment_template?

would something like be possible re: deploying in different environments? was trying to avoid having multiple local files

gitlab-ci.yml

    ...
    b95f089f-6679-410f:
      extends:
        - .deployment_template
      stage: deployment
      environment:  
        name: development
      variables:
        DOMAIN_NAME: "dev.company.io"
        BRANCH: develop
        RELEASE_NAME: service-reco-mgr-b95f089f-6679-410f-v1-0
        EXTRA_VALUES_FILE: values_b95f089f-6679-410f_dev.yaml

    84a5b44f-98c7-4322:
      extends:
        - .deployment_template
      stage: "staging"
      environment:  
        name: staging
      variables:
        DOMAIN_NAME: "staging.company.io"
        BRANCH: master
        RELEASE_NAME: service-reco-mgr-84a5b44f-98c7-4322-v1-0
        EXTRA_VALUES_FILE: values_84a5b44f-98c7-4322_stg.yaml
 

.deployment_template

.deployment_template: 
  stage: development
  image: alpine/helm:latest
  variables:
    DOMAIN_NAME: "dev.company.io"
  before_script:
    - touch ${ROOT_HELM_REPOSITORY}/values_${ENV}.yaml
    ...
    ...
  script:
    ...
    ...
  environment:
    name: development
    url: http://${RELEASE_HOST}
  tags:
    - ${stage}
  when: manual
  allow_failure: false
  only:
    - ${BRANCH}

trying lots of different things to get the gitlab-ci to pass stage, environment, branch into the extension of .deployment_template

any help would be appreciated

I don’t think you can use variables in tags BTW, but this looks like about right. What error are you getting exactly?

I usually use YAML anchors rather than extends, but I do something very similar:

stages:
    ...
    - deploy

.deploy: &deploy
    stage: deploy
    # VERSION_TARGET must be set in concrete deploy jobs.
    before_script:
        - ...
    script:
        - ...

deploy:staging:
    <<: *deploy
    rules:
        - if: '$CI_COMMIT_BRANCH =~ ...'
          when: on_success
        - when: never
    variables:
        VERSION_TARGET: ...
    dependencies:
        - prepare:staging
    environment:
        name: staging
        url: $ENVIRONMENT_SLUG
    tags: 
        - deploy
        - staging
...

Note that ENVIRONMENT_SLUG is set in the CI/CD settings for the project, but I could have defined it in the file and used the a CI_ENVIRONMENT_SLUG predefined variable.

it wasn’t recognizing the stage and that might have to be declared before the variables come into play hence the error. I just created another template.