If rule condition for feature branch in gitlab-ci.yml

I have a requirement, where i would like to build image and deploy my code on dev environment, but only when i merge my code to remote feature branch. That feature branch name changes every time, means it is based on jira ticket number.

I have two options is my mind:

  1. using $CI_MERGE_REQUEST_TARGET_BRANCH_NAME as below.
build_docker_image:
  extends:
    
.build_docker_image
.test_variables
rules:# Dev/Staging/QA all use the same envs for docker builds. Also allow for any MRs to build.
if: '$CI_PIPELINE_SOURCE == "merge_request_event"'

build-image-feature-branch:
  extends:
    
.build_docker_image
.dev_variables
tags:
optty-dev-containerd
rules:
- if: "$CI_COMMIT_BRANCH == $CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
- if: "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME != ['dev|staging|qa|Main']

deploy-feature-branch:
  extends:
    
.deploy_gitops_image
.dev_variables
environment:
  name: dev
tags:
optty-dev-containerd
rules:
- if: '$CI_COMMIT_BRANCH == $CI_MERGE_REQUEST_TARGET_BRANCH_NAME && $CI_PIPELINE_SOURCE != "merge_request_event"'
  when: manual
- if: "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME != ['dev|staging|qa|Main']
  when: manual
  1. Pass the value of feature branch name to a variable in gitlab-ci.yml and further variable should used in work rule’s if condition.
    The feature-branch name would be in another file of app code. whenever user tries to merge the code into remote feature braanch, he/she will assign a value to feature-branch name in that file and merge the code. So once the pipeline triggers, that should be passed and runs the job where condition is written for feature-branch. Below is structure of gitlab-ci.yml
variables:
FEATURE_BRANCH_NAME: feature-branch-name-file.txt

build_docker_image:
  extends:
    
.build_docker_image
.test_variables
rules:# Dev/Staging/QA all use the same envs for docker builds. Also allow for any MRs to build.
if: '$CI_PIPELINE_SOURCE == "merge_request_event"'

build-image-feature-branch:
  extends:
    
.build_docker_image
.dev_variables
tags:
optty-dev-containerd
rules:
if: "$CI_COMMIT_BRANCH == $FEATURE_BRANCH_NAME"

deploy-feature-branch:
  extends:
    
.deploy_gitops_image
.dev_variables
environment:
  name: dev
tags:
optty-dev-containerd
rules:
if: '$CI_COMMIT_BRANCH == $FEATURE_BRANCH_NAME && $CI_PIPELINE_SOURCE != "merge_request_event"'
  when: manual

and value in that app code file feature-branch-name-file.txt should be like
branch_name: <jira_ticket_number>

Please guide me

Thanks in advance