How to get the URL of the repository in which a script resides (not the one which executes the pipeline)

How to get URL of the repository in which a script resides?

I have two Gitlab repos A and B.

A contains a .gitlab-ci.yml including a script from B

  - project: path/to/B
    ref: main
    file: template/.gitlab-ci-common.yml

In addition to including a generic script from B, I also need to fetch some files from B. To reach them want to do a soft git clone of B. Since it is a generic reusable functionality, I want to have it in template/.gitlab-ci.yml of B:

git clone --depth 1 https://gitlab-ci-token:${CI_JOB_TOKEN}@${B_REPOSITORY_URL} $TMP_FOLDER/pipeline

But if I use CI_REPOSITORY_URL it refers (correctly) to A, because the pipeline is executed from A.

How to refer to the repository of B from within template/.gitlab-ci.yml ?

Thanks for hints.

There is no way to refer to the GIT repository, because the pipelines are running in a scope of Project A and the include is done behind the scenes.

You could use a variable to define the project B path - see Use CI/CD configuration from other files | GitLab

And then do some magic in the git clone

  - project: '${PROJECT_B_PATH}'
    ref: main
    file: template/.gitlab-ci-common.yml

    - git clone --depth 1 https://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}/${PROJECT_B_PATH} $TMP_FOLDER/pipeline

Thanks for response. This is actually how I am doing it at present, but thought there is a solution that won’t require duplication of the PROJECT_B_PATH.

Anyway, even project: '${PROJECT_B_PATH}' was not working for me, had to hard code the URL (or path) there - if I could avoid at least that, would be good.