Expose fork's upstream/root project and default branch as CI variables

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Problem to solve

I'm starting to look at extracting some of our common CI job steps/templates so they can be shared with other projects, via include, making it easier to manage some of these centrally. One thing that jumps out at me is our deploy jobs/templates are all basically the same but for the projects where the team prefers a fork based model we restrict the job to only running on the default branch of the root project with something like:

...
  only:
    - master@foo-group/bar-team/baz-service

Further details

If the project's root project was exposed as a CI variable we could use something like:

...
  only:
    - master@${CI_ROOT_PROJECT_PATH}

If the default branch was also exposed as a CI variable we could use something like:

...
  only:
    - ${CI_PROJECT_DEFAULT_BRANCH}@${CI_ROOT_PROJECT_PATH}

which would be useful for projects that change the default branch but still want to use the same template.

Proposal

Add the projects' root project (itself if it's not a fork) variables to the CI project predefined variables. I'd just duplicate the existing CI_PROJECT_* ones as CI_ROOT_PROJECT_*:

CI_ROOT_PROJECT_DIR
CI_ROOT_PROJECT_ID
CI_ROOT_PROJECT_NAME
CI_ROOT_PROJECT_NAMESPACE
CI_ROOT_PROJECT_PATH
CI_ROOT_PROJECT_PATH_SLUG
CI_ROOT_PROJECT_URL
CI_ROOT_PROJECT_VISIBILITY

I'd also like to see the following variables added:

CI_PROJECT_DEFAULT_BRANCH
CI_ROOT_PROJECT_DEFAULT_BRANCH

Links / references

Edited by 🤖 GitLab Bot 🤖