Failed to get all commited changed files in gitlab-ci.yml

I have two branches, one is master, the other is feat/test. For some reason, I have to get all changed files in multiple commits of a merge request in gitlab-ci.yml. So I wrote the script like this:

variables:
  GIT_STRATEGY: clone
  GIT_DEPTH: 0
script:
    - echo $CI_COMMIT_REF_NAME
    - echo $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
    - export CHANGED_FILES="`git diff --no-commit-id --name-only -r origin/${CI_COMMIT_REF_NAME} ${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME}`"
    - echo "All changed files are below"
    - echo "${CHANGED_FILES}"

The CI_COMMIT_REF_NAME can be logged, which is master. However, I couldn’t get the CHANGED_FILES or CI_MERGE_REQUEST_SOURCE_BRANCH_NAME. They just logged nothing. So is there any way to get all commited changed files in gitlab-ci.yml? I have checked many solutions in the gitlab forum but none of them worked for me.

This is whats I am using

variables:
    GIT_DEPTH: 0 # needed for the git diff/log to work properly
script:
    - apt-get update
    - apt-get install -y git
   # get all changed files in MR
    - if [ "${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}x" != "x" ]; then git fetch origin "${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}"; export FILES=$(git diff --name-only origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}...); fi
   # get all changed files for commits in default branch
    - if [ "${CI_COMMIT_REF_NAME}" = "${CI_DEFAULT_BRANCH}" ]; then git fetch origin "${CI_COMMIT_REF_NAME}"; export FILES=$(git diff --name-only "${CI_COMMIT_BEFORE_SHA}" HEAD); fi