Referencing variables into gitlab pipeline - auth credentials - Error 401: Unauthorized

I am running the following pipeline locally by using gitlab-ci-local. That pipeline is executing a python script that setup authentication against bitbucket and trigger a pipeline on bitbucket. This is my .gitlab-ci.yml file.

stages:
  - deploy

variables:
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
  # Here the credentials to sign in with bitbucket.
  BITBUCKET_USERNAME: ${BITBUCKET_USERNAME}
  BITBUCKET_APP_PASSWORD: ${BITBUCKET_APP_PASSWORD}

.deploy:
  stage: deploy
  image: python:3.11
  script:
  - export HASH=$(git submodule status "context/${REPOSITORY}" | sed -E 's/^.(\b[0-9a-f]{7})[0-9a-f]{33} .*$/\1/')
  - echo "Deploying ${REPOSITORY} ${HASH} to GCP project ${GCP_PROJECT}"
  - deploy/ci/bitbucket/bitbucket_trigger.py "${REPOSITORY}" ${HASH} ${GCP_PROJECT} --wait
  environment:
    name: "${REPOSITORY}-${GCP_PROJECT}"

# Here I defined hidden jobs to configure the repository projects will be deployed
.deploy:platform-infrastructure:
  extends:
  - .deploy
  variables:
    REPOSITORY: my-infra-repo

.deploy:core:
  extends:
  - .deploy
  variables:
    REPOSITORY: my-core-repo

# Here, I define the GCP project environment where the above projects repo will be deployed
deploy:platform-infrastructure:my-test-env:
  extends: .deploy:platform-infrastructure
  variables:
    GCP_PROJECT: my-test-env

deploy:core:my-test-env:
  extends: .deploy:core
  needs:
  - deploy:platform-infrastructure:my-test-env
  variables:
    GCP_PROJECT: my-test-env

When I executed the pipeline locally with gitlab-ci-local command, it is successfully finished.

> gitlab-ci-local
parsing and downloads finished in 44 ms
deploy:platform-infrastructure:my-test-env starting python:3.11 (deploy)
deploy:platform-infrastructure:my-test-env copied to docker volumes in 2.52 s
deploy:platform-infrastructure:my-test-env $ export HASH=$(git submodule status "context/${REPOSITORY}" | sed -E 's/^.(\b[0-9a-f]{7})[0-9a-f]{33} .*$/\1/')
deploy:platform-infrastructure:my-test-env $ echo "Deploying ${REPOSITORY} ${HASH} to GCP project ${GCP_PROJECT}"
deploy:platform-infrastructure:my-test-env > Deploying platform-infrastructure 4ecbf3c to GCP project my-test-env
deploy:platform-infrastructure:my-test-env $ deploy/ci/bitbucket/bitbucket_trigger.py "${REPOSITORY}" ${HASH} ${GCP_PROJECT} --wait
deploy:platform-infrastructure:my-test-env > still running...
....

 PASS  deploy:platform-infrastructure:my-test-env 
 PASS  deploy:core:my-test-env                
deploy:platform-infrastructure:my-test-env environment: { name: platform-infrastructure-my-test-env }
deploy:core:my-test-env environment: { name: core-my-test-env }

and new pipelines are triggered on the bitbucket side on the referenced projects repository the GitLab pipeline refers to. So until here when testing locally the GitLab pipeline everything works as expected.

The problem arises when pushing my changes to Gitlab, when triggering the pipeline on gitlab.com, it is failing and indicating an Error 401: Unauthorized error message

File "/usr/local/lib/python3.11/urllib/request.py", line 643, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 401: Unauthorized

I guess there is a problem when trying to authenticate to bitbucket, but not sure why, since I am defining the BITBUCKET_USERNAME and BITBUCKET_APP_PASSWORD variables here at project scope in gitlab in this way:

In addition, the above-configured variables work well for other versions of this pipeline on another branches.
So I guess, is there something wrong with the way I am calling the values of those variables in the above configuration pipeline? Not sure, since it is just shell variables and it works on my machine well.

On the other hand, in my local machine, when using gitlab-ci-local to test my work, I am using docker in docker and referencing the BITBUCKET_USERNAME and BITBUCKET_APP_PASSWORD variables inside the $HOME/.gitlab-ci-local/variables.yml file to make them work inside the local container the local runner uses:

cat variables.yml 
---
global:
  BITBUCKET_USERNAME : <my-username>
    BITBUCKET_APP_PASSWORD: <my-token-passwd> 
  PRIVILEGED: true
  VOLUME: certs:/certs/client
  VARIABLE: "DOCKER_TLS_CERTDIR=/certs"
  DOCKER_BUILDKIT: 1
  GCP_SA_KEY_B64: 
    type: file
    values:
      '*': <REDACTED>

If someone can give me a clue about what is going on on GitLab, I will appreciate it.

Now the above pipeline is reaching the variables defined for bitbucket.
What I did was expand their variable reference here for both
GitLab says that by default that expansion is not allowed for variables defined inside scripts or via exports Where variables can be used | GitLab

image