Skip to content

New predefined environment variable request: `CI_PROJECT_ROOT_NAMESPACE`

Problem to solve

There is no predefined variable that provides only the name of the root namespace.

Intended users

Anyone who uses .gitlab-ci.yml.

Proposal

Provide a new predefined environment variable named CI_PROJECT_ROOT_NAMESPACE. This variable would act similarly to the existing CI_PROJECT_NAMESPACE variable except that it would only return the root namespace. For example:

CI_PROJECT_NAMESPACE CI_PROJECT_ROOT_NAMESPACE
my-username my-username
root-group/child-group/grandchild-group root-group

Further details

Some of our features rely/make use of the root namespace. For example, GitLab NPM packages must be scoped to the root namespace:

Packages must be scoped in the root namespace of the project.

Workaround

It is fairly straightforward to extract the root namespace from CI_PROJECT_NAMESPACE:

CI_PROJECT_NAMESPACE="root-group/child-group/grandchild-group"
echo ${CI_PROJECT_NAMESPACE%%/*}
root-group

However, it would be more convenient if this value was available without this additional work.

Documentation

If this new variable is added, we would need to document it on the Predefined environment variables page.

Edited by Nathan Friend