New predefined environment variable request: CI_PROJECT_SUB_NAMESPACE
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Related to #220834 (closed).
Problem to solve
There is no predefined variable that provides only the the sub namespace.
Intended users
Anyone who uses .gitlab-ci.yml
.
Proposal
Provide a new predefined environment variable named CI_PROJECT_SUB_NAMESPACE
. This variable would act similarly to the existing CI_PROJECT_ROOT_NAMESPACE
variable except that it would only return the sub namespace. For example:
CI_PROJECT_NAMESPACE |
CI_PROJECT_ROOT_NAMESPACE |
CI_PROJECT_SUB_NAMESPACE |
---|---|---|
my-username |
my-username |
`` |
root-group/child-group/grandchild-group |
root-group |
child-group/grandchild-group |
Further details
Some of GitLab's features rely/make use of the sub namespace. For example, GitLab Pages allows accessing branch artifacts using special URLs as can be seen in this accepted StackOverflow answer:
Workaround
It is fairly straightforward to extract the sub namespace from CI_PROJECT_NAMESPACE
with CI_PROJECT_ROOT_NAMESPACE
:
❯ CI_PROJECT_NAMESPACE="root-group/child-group/grandchild-group"
❯ CI_PROJECT_ROOT_NAMESPACE="root-group"
❯ echo ${CI_PROJECT_NAMESPACE#${CI_PROJECT_ROOT_NAMESPACE}/}
child-group/grandchild-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.
Additional Suggestion
This suggestion is more of an after-thought and not subject of this issue
In case accessing job artifacts as noted above should be elevated to a supported feature it might make sense to additionally introduce another variable named CI_PAGES_JOB_ARTIFACTS_URL_PREFIX
or similar, that would store the value https://$CI_PROJECT_ROOT_NAMESPACE.$CI_PAGES_DOMAIN/-/$CI_PROJECT_SUB_NAMESPACE/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts
for more convenient construction of GitLab Pages based branch review app URLs in GitLab-CI. Though this might be less trivial and worthy of its own issue.