Description
There are other feature request and bugs that have been submitted related to this problem, but none of them encompass the full set of issues that could be solved by implementing a proper solution. I'm going to attempt to consolidate all those into one issue.
Is your feature request related to a problem? Please describe
Currently the environment variable RepoPattern only supports simple repo structures of the type "/" and simple glob matching where a glob takes the place of one of those two variables. The lack of support for more complex repo structures and advanced matching introduces the following problems.
- Environment variable scopes are broken in any multi-level Gitlab repo.
Setting SECRET_KEY = XYZ
with the scope company/*
will not be loaded in a Gitlab repo of the structure company/subgroup/testrepo
.
- Environment variables need to be managed in a redundant manner.
If I would like SECRET_KEY = XYZ
available in the repos company/db
and company/frontend
but not company/public
I would need to create two different environment variables and remember to change both of them instead of setting an environment variable with the pattern company/{db,frontend}
.
- Environment variables cannot be excluded from domains using NOT logic.
I would like SECRET_KEY = XYZ
credentials to be available in any dev environment matches the pattern company/!(internship*)
Describe the behaviour you'd like
Environment variable matching patterns should support the full set of glob-style matching features that developers expect including:
- Globstar
**
matching - Matching at multiple repo layers deep
- Brace expansion,
{a,b}
- NOT matching with
!
Describe alternatives you've considered
- Manually running
eval $(gp env -e)
after workspace creation can load variables with the basic patterncompany/*
in nested Gitlab repos - There is no alternative for matching at deeper gitlab nested repos.
- Alternatives for brace expansion include managing redundant ENV variables for each separate context.
- There is no alternative the lack of negate matching.
Related Issues
The following pre-existing issues would be solved by this feature/request:
- Environment scope doesn't apply consistently for GitLab subgroups #8618
- Scope wildcards in user environment variables not working #13474
- Allow multiple scopes in env variables #12877
- regex support for environment variable scope #7822 (Closed as duplicate, referenced)
- More flexible environment variable wildcard scopes #6316 Closed as stale, but never resolved.
Two attempted fixes that were merged but did not actually solve the issue:
- Unable to set user environment variables for GitLab repos with nested groups #2702 ( This issue introduced a workaround to load scoped environment variables via the
gp
CLI, but does solve the full scope of the problems. ) - Environment Variables and org/rep #1358
Additional context
There is an inconsistency between what environment variables that get loaded during workspace creation/launch and which environment variables get loaded by eval $(gp env -e)
I have not tested whether project environment variables are subject to the same problems and limitations.
Possible Implementation Notes:
The easiest way to enable full advanced glob pattern matching is probably by using switching the WorkspaceEnvVarAccessGuard to use minimatch.
The score function would need to be changed to resolved environment variable conflicts at any layer of depth. Perhaps a function where the score added for an exact match at a given level of depth is 2^(22-depth)
. (Gitlab supports up to 20 layers of nested subgroups). With this score function higher score would have priority.
The various places that use splitRepositoryPattern
like this one would need to be modified.
Additional tests like these ones should be added to test for proper multi-level repo pattern scoping.